Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default_app_config for Django with apps directory structure?

Tags:

python

django

I want to declare default_app_config variable for my app, but I have an error:

django.core.exceptions.ImproperlyConfigured: Cannot import 'accounts'. Check that 'apps.accounts.apps.AccountsConfig.name' is correct.

All my apps is located in directory apps:

project_name/
apps/
   app1/
   app2/
   ....
   accounts/

I am using my apps like this:

INSTALLED_APPS = [
  # Local Apps
  'apps.category',
  'apps.products',
  'apps.cart',
  'apps.orders',
  'apps.accounts',
  'apps.attributes',
  'apps.pages',
  'apps.compare',
  'apps.filters',
  'apps.brands'
]

And now when I want to set default_app_config for my app, I get the error above.

__init__.py in app folder:

default_app_config = 'apps.accounts.apps.AccountsConfig'

apps.py in app folder:

from django.apps import AppConfig


class AccountsConfig(AppConfig):
    name = 'accounts'
    verbose_name = 'Пользователи'

Why I get the error?

like image 804
Григорий Дикий Avatar asked Jun 05 '17 07:06

Григорий Дикий


People also ask

What is AppConfig Django?

The AppConfig class used to configure the application has a path class attribute, which is the absolute directory path Django will use as the single base path for the application.

Where can I find app name in Django?

You can get application name from model: Book. _meta. app_label .


1 Answers

AppConfig name is full python path to the application. So try...

name = 'apps.accounts'
like image 82
Raja Simon Avatar answered Oct 17 '22 07:10

Raja Simon