为了账号安全,请及时绑定邮箱和手机立即绑定

django 表单不在帖子内

django 表单不在帖子内

慕斯709654 2023-05-23 16:35:25
我只是想能够读取用户在服务器表单上输入的值。我注意到它永远不会进入视图函数的这一部分 if request.method == 'POST':如果我遗漏了什么,请告诉我。我已经包含了我的视图、url、表单、html 文件的代码片段:urls.py=>urlpatterns = [    path('create',views.create),    path('create/',views.create),    path('download', views.download),]checklistform.py=>class ContactForm(forms.Form):    name = forms.CharField()create.html=><!DOCTYPE html><html lang="en><head></head><body> <form method="POST">    {% csrf_token %}    {{ form.as_p }}    <input type="submit" value="OK"> </form></body></html>views.py =>from django.shortcuts import render, HttpResponseRedirect, HttpResponse, redirectfrom .checklistform import ContactFormdef create(request):    print("letssee")    print(request.method)    if request.method == 'POST':        form = ContactForm(request.POST)        if form.is_valid():            name = form.cleaned_data['name']            print(name)    form=ContactForm()    return render(request, 'create.html', {'form': form})在 pycharm => 中看到的输出(我们可以看到它永远不会进入 if)[15/Aug/2020 23:47:03] "GET / HTTP/1.1" 404 2038letsseeGET[15/Aug/2020 23:47:08] "GET /imschecklist/create HTTP/1.1" 200 364
查看完整描述

1 回答

?
函数式编程

TA贡献1807条经验 获得超9个赞

<html lang="en>改为<html>. 你错过了双引号。



查看完整回答
反对 回复 2023-05-23
  • 1 回答
  • 0 关注
  • 91 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信