zoukankan      html  css  js  c++  java
  • django将数据库中数据直接传到html

    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>

     

     

  • 相关阅读:
    数据结构10——最短路径
    获取JVM转储文件的Java工具类
    如何测试这个方法--性能篇
    如何测试这个方法--功能篇
    使用WireMock进行更好的集成测试
    性能测试框架第二版
    如何使用Selenium来计算自动化测试的投资回报率?
    模糊断言
    如何从测试自动化中实现价值
    如何获取JVM堆转储文件
  • 原文地址:https://www.cnblogs.com/zealousness/p/7450495.html
Copyright © 2011-2022 走看看