0x726974636879
0x726974636879

Reputation: 77

Django - apps.py not recognized

Django version 1.11.7

Trying to execute signals.py for a post_save execution my code works if i put it in my models.py file but i want to separate my signals from my models in app_1 but seems that even my apps.py isn't executed.

The project structure

my_project
├──docs
├──src
│   ├── __init__.py
│   ├── apps
│   │   ├── app_1
│   │   │     ├── __init__.py
│   │   │     ├── admin.py
│   │   │     ├── apps.py
│   │   │     ├── signals.py
│   │   │     ├── ...
│   │   │     └── models.py
│   │   ├── ...
│   │   └── app_x
│   ├── fabfile.py
│   ├── manage.py
│   ├── media
│   │   └── files
│   ├── requirements.txt
│   ├── settings.py
│   ├── static
│   │   ├── file_1.html
│   │   ├── ...
│   │   └── file_x.html
│   ├── templates
│   │   ├── app_1
│   │   ├── ....
│   │   └── app_x
│   ├── urls.py
│   └── wsgi.py

apps.py

from django.apps import AppConfig

class AppOneConfig(AppConfig):
    name = 'app_1'

    def ready(self):
        print("test")
        from . import signals

__ init __.py

default_app_config = "apps.app_1.apps.AppOneConfig"

And here is the error i have

django.core.exceptions.ImproperlyConfigured: Cannot import 'app_1'. Check that 'apps.app_1.apps.AppOneConfig.name' is correct.

settings.py, INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'apps.app_1'
]

Upvotes: 1

Views: 301

Answers (1)

Pradip Kachhadiya
Pradip Kachhadiya

Reputation: 2235

apps.py:

from django.apps import AppConfig

class AppOneConfig(AppConfig):
            ⬇⬇⬇
    name = 'apps.app_1'

    def ready(self):
        print("test")
        from . import signals

settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'apps.app_1.apps.AppOneConfig' ⬅⬅⬅⬅⬅
     
]

Upvotes: 3

Related Questions