1、當然,前提是建立和配置好django數據庫啦~
2、在python后台函數中引入需要的表
#要讀取home這個APP下的models.py文件,引入其中的Student_message_uneditable和Student_message_editable兩張數據表
from home.models import Student_message_uneditable,Student_message_editable
3、在python后台函數中查詢數據
# 獲取表中的某一條數據,用:表名.objects.get(查詢條件(等號左邊是列名,右邊是具體值))
student_message_uneditable=Student_message_uneditable.objects.get(student_id=userid)
在這里,student_message_uneditable即為查詢到的那一條數據,用student_message_uneditable.列名 即可獲得那一條數據中具體的各個數據的值
4、在python后台函數中的變量值將數據傳到html頁面
#向前端頁面將當前函數中所有的變量傳到html中,直接用render_to_response()和locals()
return render_to_response("student_center.html",locals())
4、在html頁面中使用數據
將獲取到的數據放入文本框
<input value="{{ student_message_uneditable.student_name }}">
使用獲取到的數據判斷下拉框的取值
<select name="sex" id="stu_sex" class="form-control">
<option {% if student_message_uneditable.student_sex == 1 %}selected{% endif %}>男</option>
<option {% if student_message_uneditable.student_sex == 0 %}selected{% endif %}>女</option>
</select>