mirror of https://github.com/django/django.git
Fixed #25156 -- Mentioned django.setup() in the settings overview for standalone Django use.
This commit is contained in:
parent
59c279e5e5
commit
5281f8b635
|
@ -265,7 +265,29 @@ Also, it's an error to call ``configure()`` more than once, or to call
|
|||
It boils down to this: Use exactly one of either ``configure()`` or
|
||||
``DJANGO_SETTINGS_MODULE``. Not both, and not neither.
|
||||
|
||||
.. _@login_required: ../authentication/#the-login-required-decorator
|
||||
Calling ``django.setup()`` is required for "standalone" Django usage
|
||||
--------------------------------------------------------------------
|
||||
|
||||
If you're using components of Django "standalone" -- for example, writing a
|
||||
Python script which loads some Django templates and renders them, or uses the
|
||||
ORM to fetch some data -- there's one more step you'll need in addition to
|
||||
configuring settings.
|
||||
|
||||
After you've either set :envvar:`DJANGO_SETTINGS_MODULE` or called
|
||||
``configure()``, you'll need to call :func:`django.setup()` to load your
|
||||
settings and populate Django's application registry. For example::
|
||||
|
||||
from django.conf import settings
|
||||
from myapp import myapp_defaults
|
||||
|
||||
settings.configure(default_settings=myapp_defaults, DEBUG=True)
|
||||
django.setup()
|
||||
|
||||
# Now this script can use any part of Django it needs.
|
||||
|
||||
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.
|
||||
|
||||
.. seealso::
|
||||
|
||||
|
|
Loading…
Reference in New Issue