It seems Django allows to execute the code on startup - when the app starts, however, it's not clear and where I should put the code. So how can I execute the code on startup in Django 1.7?
            Asked
            
        
        
            Active
            
        
            Viewed 6,494 times
        
    1 Answers
12
            For Django>=1.7 you can use the AppConfig.ready() callback:
https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppConfig.ready
For previous versions, see this answer.
If you are using the AppConfig.ready() method:
1) Create a myapp/apps.py module and subclass the AppConfig. For example:
from django.apps import AppConfig
class MyAppConfig(AppConfig):
    name = 'myapp'
    def ready(self):
    ...
2) Edit myapp/__init__.py and register your app config:
default_app_config = 'myapp.apps.MyAppConfig'
See https://docs.djangoproject.com/en/1.7/ref/applications/#configuring-applications for details.
 
    
    
        Matt Ellen
        
- 11,268
- 4
- 68
- 90
 
    
    
        Selcuk
        
- 57,004
- 12
- 102
- 110
