18👍
If you print out the thread ID within settings.py, you will see that settings.py is actually being loaded on two different threads.
See this stackoverflow response and this article for more info.
4👍
Actually what Django does is putting a wrapper around settings. It is basically an object (settings object if you want so) which give you access to some direct setters like settings.WHATEVER
, so it appears like you access the global variables in settings.py direclty.
I really don’t remember though, why the import happens twice. I looked into it once when I worked on django-dynamic-settings which uses a very similar approach as Django itself.
Anyway, if you are interested in the “magic” you can follow the flow starting from the execute_from_command_line
call in manage.py
.
- Django __call__() missing 1 required keyword-only argument: 'manager'
- {% load static %} and {% load staticfiles %}: which is preferred?
- Psycopg2 cannot connect to docker image
1👍
Django does some strange things with settings.py, and it will execute more than once. I’m used to seeing it imported twice, not sure why in PyCharm you’re getting four times. You have to be careful with statements with side-effects in settings.py.
- How to emit SocketIO event on the serverside
- Reset SQLite database in Django
- PyCharm – Unresolved library 'staticfiles'
- Django – http code 304, how to workaround in the testserver?
- Django can't access raw_post_data
1👍
A closely-related question has been asked at least twice since. I can add that a Django core developer rejected the idea that this is any sort of Django bug; it’s normal behavior.
Also see this from Graham Dumpleton.
- Django admin many-to-many intermediary models using through= and filter_horizontal
- Django Inline Formsets using custom form
- What is the best CouchDB backend for Django?
- Why does Django South require a default value when removing a field?