Django - include app urls

前端 未结 5 1581
余生分开走
余生分开走 2021-02-20 01:48

I have the following structure (Django 1.4):

containing_dir/
    myproject/
        myapp1/
        myapp2/
        myapp3/

myproject, myapp1,

相关标签:
5条回答
  • 2021-02-20 02:26

    You must have a

    __init__.py
    

    file inside your "myproject" directory. When you say:

    (r'^myapp1/', include('myproject.myapp1.urls'))
    

    you are saying "myproject" (as well as myapp1) is a python packege.

    0 讨论(0)
  • 2021-02-20 02:27

    Try:

    urlpatterns = [
        ...
        url(r'^app_name/', include('app_name.urls', namespace='project_name'))
        ...
    ]
    
    0 讨论(0)
  • 2021-02-20 02:33

    In myproject.settings make following changes :

    INSTALLED_APPS = (   
    [..]
    'myapp1',
    'myapp2',
    'myapp3',
    )
    
    0 讨论(0)
  • 2021-02-20 02:38

    To solve this issue just select "myproject" directory in PyCharm and set this as a source root. Your project don't know from which root it has to search for given app. It fixed the issue for me. Thank you.

    0 讨论(0)
  • 2021-02-20 02:46

    Does ROOT_URLCONF need to point to myproject.urls?

    If you place your apps inside of myproject you need to use the proper view prefix.

    urlpatterns = patterns('myproject.myapp1',
    ...
    
    0 讨论(0)
提交回复
热议问题