Start the Django shell command line

python manage.py shell

Get the student name ‘White Moon’ in the student data table

S1 = Student. Objects. The get (name = 'white month)

Find first year students in student table based on foreign key table data filtering

Student.objects.filter(grade=1).values()

Find all ‘Year 1 Chinese students’ in Student table

Student.objects.filter(grade=1,country_id=cn_id).values() # Find first year Chinese studentsCopy the code

There’s also a foreign key association, which is a more convenient way to write it

Student.objex=cts.filter(grade=1,country__name=' cn ').values() #"__

Reverse access: Having obtained the Country object, how do I access all students belonging to that Country?

Cn = country.objects.get (name=' cn ') student_set.all() Student_set student_set student_set student_set student_set student_set student_set student_set student_setCopy the code

Reverse filtering: Get the name of the country with first grade

Country.ids = student.objects.filter (grade=1).vlaues_list('country',flat=True Country.objects.filter(id__in=country.ids).values()Copy the code

Create a simple login page

def login(request): html=""" <form> <input typr="text" name="username"> <input type="password" name="password"> <input type="submit" Value =" login "> </form> "" return HttpResponse(HTML)Copy the code

GET and POST

GET obtains data from the background, and POST submits data to the background

Template separation

1. Configure TEMPLATES in setting.py

'DIRS': [os.path.join(BASE_DIR,"< HTML folder location >")], # HTML folder location

2. Logical code page views.py references HTML files

Return render(request,'< HTML file name >')