mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #26152 -- Documented how to avoid django.setup() deadlock in standalone scripts.
This commit is contained in:
parent
ecd502cfdb
commit
0fb1185538
@ -291,6 +291,17 @@ Note that calling ``django.setup()`` is only necessary if your code is truly
|
||||
standalone. When invoked by your Web server, or through :doc:`django-admin
|
||||
</ref/django-admin>`, Django will handle this for you.
|
||||
|
||||
.. admonition:: ``django.setup()`` may only be called once.
|
||||
|
||||
Therefore, avoid putting reusable application logic in standalone scripts
|
||||
so that you have to import from the script elsewhere in your application.
|
||||
If you can't avoid that, put the call to ``django.setup()`` inside an
|
||||
``if`` block::
|
||||
|
||||
if __name__ == '__main__':
|
||||
import django
|
||||
django.setup()
|
||||
|
||||
.. seealso::
|
||||
|
||||
:doc:`The Settings Reference </ref/settings>`
|
||||
|
Loading…
Reference in New Issue
Block a user