Search code examples
pythondjangodjango-1.9

Django 1.9 can not find newapp


I have worked with django 1.7 and recently started new project with django 1.9. The major difference with starting a new app was that new app is created with apps.py file. I read on django docs that now you have to use

INSTALLED_APPS = [
    'newapp.apps.NewAppConfig',
    ...
]

(old was just 'newapp')

In my new project i have all my apps in a new directory called 'myapps'. But if i use 'myapps.newapp.apps.NewAppConfig' than django gives error ImportError: No module named newapp But if i use the old way i.e.

INSTALLED_APPS = [
    'myapps.newapp',
    ...
]

Than it works perfectly without error but configs in apps.py file may not be applied ( i don't know how it works ).

So which is the right way to put newapp in INSTALLED_APPS settings for django 1.9 when you got all your new apps in another directory like "myapps" with apps.py config file also working?


Solution

  • If your apps directory is in the myapps directory, then check the following:

    1. Your myapps directory should have an __init__.py

    2. Include myapps in the path when you include the app in INSTALLED_APPS, i.e. 'myapps.newapp.apps.NewAppConfig',

    3. Include myapps in the app config's name attribute:

      class NewAppConfig(AppConfig):
          name = 'myapps.newapp'