当我提交表单时,控制台中显示“不允许使用方法:/”。
类似这样的事情: 不允许的方法:/ [2019年3月17日18:31:18]“POST/HTTP/1.1”405
我在views.py 文件上使用它..
class UrlAccpt(View):
template_name='phc/url_accpt.html'
def get(self,request):
urlx=''
form = UrlForm(request.POST)
if request.method == 'POST':
form = UrlForm(request.POST)
if form.is_valid():
urlx= form.cleaned_data['EnterTheUrl']
form = UrlForm(request.POST)
response = TemplateResponse(request,self.template_name,{'form':form,'value':urlx})
return response
在 forms.py 文件中...我使用此代码
from django import forms
class UrlForm(forms.Form):
EnterTheUrl=forms.CharField(max_length=1000)
最佳答案
欢迎来到基于类的 View :
您需要在类中指定 post 函数。 Get 函数仅在 GET 方法上触发,不适用于 POST 请求。
添加以下功能并将您的帖子逻辑移至此处...
def post:
...
看看docs
关于django - 不允许的方法 :/(Django-Post Method),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55210567/