[Fixed]-Django – include app urls

8👍

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.

5👍

In myproject.settings make following changes :

INSTALLED_APPS = (   
[..]
'myapp1',
'myapp2',
'myapp3',
)
👤Tejas

1👍

Try:

urlpatterns = [
    ...
    url(r'^app_name/', include('app_name.urls', namespace='project_name'))
    ...
]

0👍

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👍

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.

👤Codex

0👍

Recently, In new versions of Django introduces path(route, view, kwargs=None, name=None) instead of old url() regular expression pattern.

You must have __init__.py file in app folders to recognize it as a package by django project i.e myproject

Django project i.e. myproject urls.py file must be updated to include examples like:

path('', include('django_app.urls'))
path('url_extension/', include('django_another_app.urls'))

Above example includes two apps urls in it. One is without adding any extension to path in url and another is with extension to path in current url.

Also, Do not forget to add django apps in INSTALLED_APPS in settings.py file to recognise it as app by django project something like this.

ROOT_URLCONF = 'myproject.urls'
INSTALLED_APPS = [
...
django_app,
django_another_app
...
]

For more information look at documentation.

Leave a comment