Dejell
Dejell

Reputation: 14317

Django custom app config

I would like to run code that will be executed only once in django app.

my structure:

company
  project
    common
      project_config.py
  __init__.py

__init__.py:

default_app_config = "company.project.common.ProjectConfig"

settings.py:

..
INSTALLED_APPS = (
  "company.project"
)
..

ProjectConfig.py:

from django.apps import AppConfig

class ProjectConfig(AppConfig):
    name = "company.project"

    def ready(self):
        do_something()

I don't see that the method of ready() in my config is being called.

What is wrong?

Upvotes: 2

Views: 3440

Answers (1)

afilardo
afilardo

Reputation: 527

According to the documentation, you dont need _init_.py file, just point INSTALLED_APPS up to AppConfig subclass:

Try this:

INSTALLED_APPS = (
  'company.project.common.ProjectConfig',
)

Upvotes: 6

Related Questions