Felix Eklöf
Felix Eklöf

Reputation: 3740

Django app not recognized when inside another module

I have a project with a structure like this:

my-django-project/
     venv/
     .gitignore
     README.md
     my_django_project/
          db.sqlite3
          manage.py
          my_django_project/
               settings.py
          my_first_app/
               __init__.py
               inside_app/
                    __init__.py
                    apps.py
                    serializers.py
                    models.py
                    views.py
                    ...

In settings.py i loaded the app like this:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'my_first_app.inside_app',
]

Running py manage.py runserver gives the following error:

File "C:\Users\\Documents\GitHub\tin_api_v2_test\venv\lib\site-packages\django\apps\config.py", line 246, in create      
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Cannot import 'inside_app'. Check that 'my_first_app.inside_app.apps.InsideAppConfig.name' is correct. 

However, it works fine when I don't use the Virtualenv. I've also tried putting the venv inside the django project folder to see if that would change anything but it didn't work.

Upvotes: 0

Views: 386

Answers (1)

Felix Eklöf
Felix Eklöf

Reputation: 3740

Solved it.. In apps.py of inside_app i had to change from:

from django.apps import AppConfig

class InsideAppConfig(AppConfig):
    name = 'inside_app'

to

from django.apps import AppConfig

class InsideAppConfig(AppConfig):
    name = 'my_first_app.inside_app'

Upvotes: 3

Related Questions