操作的重要步骤:提取数据内部数据---->将数据传递到HTML5界面----->判断是否是要求的值;
1.提取数据库内部数据:
all_messages = UserMessage.objects.all(name='boddy') for message in all_messages: print(message.name)
上面的错了,改成:
all_messages = UserMessage.objects.filter(name = 'boddy') for message in all_messages: print(message.name)
效果:
![img](file:///C:\Users\wangqiang\AppData\Roaming\Tencent\Users\1719655657\TIM\WinTemp\RichOle\7LITF(9J6UX@SBB`IP6_T.png)
1.1将filer变成空的效果会怎么样!
将全部的数据都提取出来了;
2.将数据传递到HTML5界面
def getform(request): # if request.method == "POST" : # name =request.POST.get('name','') # message= request.POST.get("message", '') # address = request.POST.get('address', '') # email= request.POST.get('email','') # user_message = UserMessage() # user_message.name = name # user_message.message = message # user_message.address =address # user_message.email = email # user_message.save() all_messages = UserMessage.objects.filter() if all_messages: message =all_messages[0] # for message in all_messages: # print(message.name) return render(request,'message_form.html',{"my_message":message})
程序讲解:“my_message”是程序到HTML里面的变量,message是要传递的变量。他们是通过render 进行传递的;
<label> <span>姓名 :</span> <input id="name" type="text" name="name"value="{{ my_message.name }}" class="error" placeholder="请输入您的姓名"/> <div class="error-msg"></div> </label>
在程序里面添加value量。
效果:
![img](file:///C:\Users\wangqiang\AppData\Roaming\Tencent\Users\1719655657\TIM\WinTemp\RichOle\H(FO93BIA3Q7X8$P7V%(S}P.png)