2013-08-04 93 views
1

我希望從我的儀表板頁面瀏覽鏈接時,該網址應該是/dashboard/link。 當我寫url(r'dashboard/inbox/','apps.dashboard.views.inbox', name = 'grabhalo_inbox'),它確實讀取我提供的views參數。Django的urls.py查詢

而是當我寫url(r'inbox/','apps.dashboard.views.inbox', name = 'grabhalo_inbox'),時,我得到預期的輸出,但URL是/inbox。我想要的是/dashboard/inbox

我哪裏錯了?

這裏是我的根urls.py文件

​​

這裏是我的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'), 
    ) 

回答

1

只需添加^$(開始和結束字符串)到您的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處理。

+0

Whollaaa ...謝謝:) – PythonEnthusiast