Django 查询数据库并返回页面的例子

yipeiwu_com6年前Python基础

views.py 视图文件

  message = None
  all_message = UserMessage.objects.filter(name='测试2')
  if all_message:
    message = all_message[0]
 
  return render(request, 'message_form.html',{
    'my_message':message
  })

.html 模板文件

<input id="name" type="text" name="name" class="error" value="{{ my_message.name }}" placeholder="请输入姓名"/>

以上这篇Django 查询数据库并返回页面的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python中字典(dict)合并的四种方法总结

Python中字典(dict)合并的四种方法总结

本文主要给大家介绍了关于Python中字典(dict)合并的四种方法,分享出来供大家参考学习,话不多说了,来一起看看详细的介绍: 字典是Python语言中唯一的映射类型。 映射类型对象...

python通过Windows下远程控制Linux系统

python通过Windows下远程控制Linux系统

一、学习目标 【通过Windows下远程控制Linux系统实现对socket模块认识】 二、实验环境 Windows下(模拟客户端 [ IP:192.168.43.87 ] ):pyth...

浅谈tensorflow中张量的提取值和赋值

浅谈tensorflow中张量的提取值和赋值

tf.gather和gather_nd从params中收集数值,tf.scatter_nd 和 tf.scatter_nd_update用updates更新某一张量。严格上说,tf.ga...

django model去掉unique_together报错的解决方案

事情是这样的,我有一个存储考试的表 class Exam(models.Model): category = cached_fields.ForeignKeyField(Categ...

pytorch-神经网络拟合曲线实例

pytorch-神经网络拟合曲线实例

代码已经调通,跑出来的效果如下: # coding=gbk import torch import matplotlib.pyplot as plt from torch.auto...