我有一个带有以下视图的url设置( url在应用程序中,应用程序url包含在项目中):
url(r'^details/(?P<outage_id>\d+)/$', 'outage.views.outage_details'),
def outage_details(request, outage_id=1):
outage_info = Outages.objects.filter(id=outage_id)
return render_to_response('templates/outage/details.html', {'outage_info': outage_info}, context_instance=RequestContext(request))当我单击来自http://localhost:8000的链接时,浏览器中的url将按应有的方式更改为http://localhost:8000/outage/details/1,但是视图没有呈现正确的模板。页面保持不变。我没有收到任何错误,url在浏览器中更改,但details.html模板不呈现。数据库中有一个ID为1的中断。
有什么想法吗?
发布于 2014-02-07 18:08:57
正则表达式r'^details/(?P<outage_id>\d+)/$'与http://localhost:8000/outage/details/1不匹配。但是,它应该与表达式r'^outage/details/(?P<outage_id>\d+)/$'相匹配。
也许,您可以发布整个urls.py,以找出哪个视图实际上正在被调用,因为您没有收到任何错误。我怀疑你的主页被所有的网址都打电话了。
发布于 2014-02-07 18:31:56
这是我的url设置:
项目/urls.py
urlpatterns = patterns('',
url(r'^$', 'outage.views.show_outages'),
url(r'^inventory/', include('inventory.urls')),
url(r'^outage/', include('outage.urls')),
url(r'^login', 'django.contrib.auth.views.login', {'template_name': 'templates/auth/login.html'}),
url(r'^logout', 'django.contrib.auth.views.logout', {'next_page': '/'}),
url(r'^admin/', include(admin.site.urls)),)
中断/urls.py
urlpatterns = patterns('',
url(r'^', 'outage.views.show_outages'),
url(r'^notes/(?P<outage_id>\d+)/$', 'outage.views.outage_notes', name='notes'),)
从那以后,我把细节改成了笔记,因为我在另一个应用程序中有另一个页面,里面有一个细节网址,我不想让它弄得很混乱。
https://stackoverflow.com/questions/21632005
复制相似问题