1, of course, the premise is to set up and configure the Django database ~
2. introduce the required tables in the Python backend function
#要读取home这个APP下的models. py file, introducing the student_message_uneditable and student_message_editable two datasheets
from home.models import student_message_uneditable,student_message_editable
3. Querying data in the Python backend function
# Get a piece of data in the table, using: Table name. objects.get (the query condition (the column name to the left of the equals sign, the right is the specific value))
Student_message_uneditable=student_message_uneditable.objects.get (Student_id=userid)
here,student_message_uneditable is the query to the data, with student_message_uneditable. column name to get the value of the individual data in that piece of data
4 . The value of the variable in the python backend function passes the data to the HTML page
#向前端页面 will be All the variables in the current function are passed to the HTML, directly using Render_to_response () and locals ()
return render_to_response ("student_center.html", Locals ())
4. using Data in HTML pages
Put the acquired data into a text box
<input value="{{ student_message_uneditable. Student_name }}">
Use the obtained data to determine the value of the drop-down box
<select name="Sex" id="Stu_sex" class="Form-control" >
<option {% if student_message_uneditable. Student_sex = = 1%}selected{% endif %}> man </option>
<option {% if student_message_uneditable. Student_sex = = 0%}selected{% endif %}> female </option>
</Select>
Django uploads data from the database directly to the HTML