Django - Import views from separate apps

后端 未结 5 839
轻奢々
轻奢々 2021-02-19 07:59

I\'m new to Django and working my way through \"The Django Book\" by Holovaty and Kaplan-Moss. I have a project called \"mysite\" that contains two applications called \"books\

5条回答
  •  逝去的感伤
    2021-02-19 08:42

    The URLconfs documentation gives an example of the same situation

    You can skip the imports and separate the urls by app as such:

    urlpatterns = patterns('books.views',
        (r'^/book/search/$', 'search'), #calls books.views.search
    )
    
    urlpatterns += patterns('contact.views', #make note of the '+='
        (r'^/contact/search/$', 'search'), #calls contact.views.search
    )
    

提交回复
热议问题