1

我希望在从我的仪表板页面浏览链接时,该 url 应该是/dashboard/link. 当我写url(r'dashboard/inbox/','apps.dashboard.views.inbox', name = 'grabhalo_inbox'),它时,它确实会读取我views提供的论点。

相反,当我编写时,url(r'inbox/','apps.dashboard.views.inbox', name = 'grabhalo_inbox'),我得到了预期的输出,但 url 是/inbox. 我想要的是/dashboard/inbox

我哪里错了?

这是我的根urls.py文件

urlpatterns = patterns('',
    (r'^',include('apps.auth.urls')),
    (r'^',include('apps.dashboard.urls')),
    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':settings.MEDIA_ROOT}),
    url(r'^admin/', include(admin.site.urls)),
)

这是我的dashboard.urls.py

urlpatterns = patterns('',
    url(r'dashboard/','apps.dashboard.views.dashboard', name = 'grabhalo_dashboard'),
    url(r'sent/','apps.dashboard.views.sent', name = 'grabhalo_sent'),
    url(r'inbox/','apps.dashboard.views.inbox', name = 'grabhalo_inbox'),
    )
4

1 回答 1

1

只需将^and $(字符串的开头和结尾)添加到您的dashboard/url 正则表达式:

urlpatterns = patterns('',
    url(r'^dashboard/$','apps.dashboard.views.dashboard', name = 'grabhalo_dashboard'),
    url(r'^sent/$','apps.dashboard.views.sent', name = 'grabhalo_sent'),
    url(r'^dashboard/inbox/$','apps.dashboard.views.inbox', name = 'grabhalo_inbox'),
    )

然后,http://mydomain.com/dashboard/将由apps.dashboard.views.dashboard视图处理, http://mydomain.com/dashboard/inbox/- 由apps.dashboard.views.inbox.

于 2013-08-04T04:50:40.343 回答