我遇到了Django URL的奇怪行为。尽管预测/上传网址是在urls.py中定义的,但Django在说
找不到页面(404)
Request Method: POST
Request URL: http://localhost:8000/forecast/upload/
Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order:
polls/
admin/
forecast/ [name='index']
forecast/ **forecast/upload/** [name='upload']
forecast/ help.html [name='help']
The current path, **forecast/upload/**, didn't match any of these.
项目url.py:
from django.contrib import admin
from django.urls import include, path
from django.conf.urls import url
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
path('forecast/', include('forecast.urls')),
]
应用urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
#url(r'^$', views.home, name="home"),
path('forecast/upload/', views.upload, name="upload"),
path('help.html', views.help, name="help"),
]
答案 0 :(得分:0)
您已两次指定“预测”;一次在项目级别,一次在应用程序中。因此,您的网址将是“预测/预测/上传”。
大概是您不想要的,在这种情况下,您应该从应用程序网址中的模式中删除“预测”。