Make Django not a lazy module, for ease of development

I notice that Django lazy-loads the modules that are used in the project. When I first start the server in debugging on my local computer and then load the page from the site, the debugger tells me that Django just imported more than a hundred modules.

I want Django to import all the modules at startup and not wait for the first request. This will make my development more convenient, since I do not have to wait more time for each first request.

Is it possible?

+4
source share
2 answers

I ended up just adding a section like this to my manage.py, right before the execute_from_command_line line:

 argv_string = ' '.join(sys.argv) if ('gunicorn' in argv_string) or ('runserver' in argv_string): import all_my_stuff 
0
source

It looks like this library: https://github.com/ojii/django-load , which is pretty simple, has a module loading function from Django. If you combine this technique with a Django entry point hook (e.g. http://eldarion.com/blog/2013/02/14/entry-point-hook-django-projects/ ), you should be able to explicitly load your modules when start up. (I have not tried it myself, but it looks doable.)

0
source

Source: https://habr.com/ru/post/1496890/


All Articles