2017-10-05 4 views
0

私は、各アプリケーションで独自のurlパターンを使用して、include /を使ってメインプロジェクト/アプリケーションに組み込むことができます。同じアプリケーションのurlパターンをグループ化することは可能ですか?django

アプリにいくつかの異なるURLがあるのだろうか、それをグループ化する方法はありますか?例えば

urlpatterns = [ 
    url(r'^user/$', hello.asView(), 
    url(r'^user/hello/$', hello.asView(), 
    url(r'^user/there/$', hello.asView(), 
    url(r'^user/here/$', hello.asView(), 
    url(r'^user/that/$', hello.asView(), 
    url(r'^user/mini/$', hello.asView(), 
    url(r'^user/max/$', hello.asView(), 

    url(r'^bb/$', hello.asView(), 
    url(r'^bb/hello/$', hello.asView(), 
    url(r'^bb/there/$', hello.asView(), 
    url(r'^bb/here/$', hello.asView(), 
    url(r'^bb/that/$', hello.asView(), 
    url(r'^bb/mini/$', hello.asView(), 
    url(r'^bb/max/$', hello.asView(), 
] 

無視してくださいすべてのhello.asView()グループ化する方法があります場合、私は疑問に思って、すべてのより多くのURLが存在する場合userbbはそう、私はuserを入力の上に維持する必要はありません。またはbb

ありがとうございました。

答えて

0

あなたは、一致パターン

url(r'^user/(?P<page>[\w-]+)/$', hello.asView(), 

を使用することができますし、ページが有効であれば、あなたのビューで、あなたは確認することができます。あなたがページリストを持っているとしましょう。あなたはこれを行うだけです:

def get(self, page): 
    page_list = ['hello', 'there', 'here'] 
    if page not in page_list: 
     return HttpResponse(status=404) 
    return HttpResponse(status=200) 
関連する問題