我只是想能夠讀取用戶在服務器表單上輸入的值。我注意到它永遠不會進入視圖函數的這一部分?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
提交
取消