【发布时间】:2017-10-13 12:52:19
【问题描述】:
我正在使用 NGINX 和 UWSGI 运行 Django 应用程序。
我的 URL 模式曾经是这样的:
urlpatterns = [
url(r'^$', views.index),
url(r'^binaryQuestionApp/',include('binaryQuestionApp.urls')),
url(r'^pointlocations/',include('pointlocations.urls')),
url(r'^attributesFromPointsApp/',include('attributesFromPointsApp.urls')),
url(r'^admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
然而,我想把它改成这样:
urlpatterns = [
url(r'^$', views.index),
url(r'^collections/',views.collections), ## new line ##
url(r'^binaryQuestionApp/',include('binaryQuestionApp.urls')),
url(r'^pointlocations/',include('pointlocations.urls')),
url(r'^attributesFromPointsApp/',include('attributesFromPointsApp.urls')),
url(r'^admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
然而,在将它推送到我的服务器后(并且 .py 文件在服务器上确实发生了变化),我一直得到 Django 的 404 页面:
Using the URLconf defined in data_collection_project.urls, Django tried these URL patterns, in this order:
^$
^binaryQuestionApp/
^pointlocations/
^attributesFromPointsApp/
^admin/
^media\/(?P<path>.*)$
The current URL, randomurltoget404page, didn't match any of these.
如果我更改其他内容,为了测试,我可以让更改生效。例如,我可以更改 url(r'^$', views.index), 最终指向的 .html 文件,该文件在我的网站上进行了更新。
如何让 Django 更新 URL 模式?相关问题告诉我重启uwsgi或nginx,我试过用sudo service uwsgi restart无济于事。
【问题讨论】:
-
删除
urls.pyc也许它从缓存中加载它? -
您正在尝试一些未在您的 url conf 中定义的随机 url?
-
@MosesKoledoye 我做了,这将提供 404 页面。事实上,在示例中,我尝试导航到
mywebsite/randomurltoget404page -
@MosesKoledoye 他想访问
/collections/,但为了进行测试,他输入了一些内容向您展示,data_collection_projects.urls甚至没有将collections显示为选项。 -
@MitchellvanZuylen 删除后你确实重新启动了 uwsgi 吗?