我写了下面这段简单的代码,我只想检查一下当访问POST方法时,它是否显示405,但它却显示page not found。在
在视图.py在
from django.shortcuts import render, redirect
from django.http import HttpResponse
from .forms import helloform
def index(request):
form = helloform()
return render(request, 'hello/index.html', {'form' : form})
def addintodb(request): #trying to invoke this function
form = helloform(request.POST)
print(request.POST)
return redirect(index)
在网址.py在
^{pr2}$在索引.html在
> form action="{% url 'addtodb' %}" method="POST" role="form" # from here
> ...
> </form>
经过一段时间后,我发现,将我的项目URL设置为“”可以提供所需的。也就是说
我的项目网址.py在
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('hello.urls')) #previously I had path('hellobfs', include('hello.urls'))
]
因此,删除我的项目网址的任何路径,使我的应用程序的网址工作没有“404”错误,有人能解释为什么吗?在
将
return redirect(index)
替换为return redirect('/', )
。您的代码应该如下所示:我想这个,作为网址.py在我的应用程序中需要项目和应用程序的URL
那就是 项目url->
应用程序的url->
^{pr2}$当我需要遍历到添加页面时,我需要提供(我犯错误的地方)
它提供了不允许的方法,为了提高可读性,我们可以在project的url中添加一个“/”
现在我们可以穿越过去了
我想你需要把你的表格保存在视图.py文件尝试添加一个,窗体保存()在您的,form=helloform之后(请求.POST)在
相关问题 更多 >
编程相关推荐