Django uploads data from the database directly to the HTML

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.