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>

     

     

  • 相关阅读:
    蓝鲸财经新闻记者实战培训
    雷军解密小米商业内核
    OpenGL6-纹理动画
    OpenGL5-纹理贴图
    OpenGL4-绘制旋转的立方体
    OpenGL3-绘制各种图元绘制
    OpenGL2-绘制三角形
    OpenGL1-创建窗口(建立Win32的OpenGL开发环境 )(代码上传)
    一步步做程序优化-讲一个用于OpenACC优化的程序(转载)
    常用编译选项介绍
  • 原文地址:https://www.cnblogs.com/zealousness/p/7450495.html
Copyright © 2011-2022 走看看