django modal + bootstrap




    
    Title
    
    




{#
#}
{% for student in student_list %} {% endfor %}
ID 姓名 年龄 性别 性别
{ { student.id }} { { student.name }} { { student.age }} {% if student.gender %} 男 {% else %} 女 {% endif %} { { student.cls.title }}
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# info:
import json

from django.shortcuts import  render,get_list_or_404,redirect,HttpResponse
from  app01.models import  Classes,Students,Teachers

def get_students(request):
    student_list=Students.objects.all()
    class_list=Classes.objects.all()
    return  render(request,'get_students.html',{"student_list":student_list,'class_list':class_list})

def add_students(request):
    response_dict={"status":True,"msg":None}
    # {stu_name: "aa", stu_age: "bb", gender: "1", class_name: "1"}  # }
    try:
        stu_name=request.POST.get('stu_name')
        stu_age=request.POST.get('stu_age')
        gender=request.POST.get('gender')
        class_id=request.POST.get('class_name')
        Students.objects.create(name=stu_name,age=stu_age,gender=gender,cls_id=class_id)
    except Exception as e:
        response_dict['status']=False
        response_dict['msg']=str(e)
    response_json=json.dumps(response_dict)
    return HttpResponse(response_json)

def edit_students(request,student_id):
    pass

转载于:https://blog.51cto.com/13606158/2080138

你可能感兴趣的:(python,json)