[英]Django urlpattern doesn't work
I created very simple project, but it shows me Django 404 error page (debug mode is On). 我创建了一个非常简单的项目,但它向我显示了Django 404错误页面(调试模式为On)。
urls.py: urls.py:
....
urlpatterns = patterns('',
(r'^news/', include('news.urls')),
)
news/urls.py: news / urls.py:
....
urlpatterns = patterns('news.views',
(r'^$', 'news'),
)
I also have "news" in INSTALLED_APPS. 我在INSTALLED_APPS中也有“新闻”。
When I open 当我打开
http://localhost/news/
in browser Django shows me 404 error: 在浏览器Django中显示404错误:
" ... Page not found. Request URL: http://localhost/news// ..."
What's wrong with my urls? 我的网址有什么问题?
您的urls.py说:“在应用news
views.py
文件中调用函数def news(request)
。此功能存在吗?
You have two slash in the end of url. 网址末尾有两个斜杠。 maybe it's answer
也许是答案
Assuming that news is ur app name and news is the view name also. 假设新闻是您的应用名称,新闻也是视图名称。 Try this in news/urls.py:
在news / urls.py中尝试以下操作:
urlpatterns = patterns('',
(r'^$', 'news.views.news'),
)
Your code should work 您的代码应该可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.