我只是想能够读取用户在服务器表单上输入的值。我注意到它永远不会进入视图函数的这一部分 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
添加回答
举报
0/150
提交
取消