~ubuntuone-pqm-team/django/stable

« back to all changes in this revision

Viewing changes to docs/topics/settings.txt

  • Committer: Natalia
  • Date: 2015-12-29 23:45:16 UTC
  • Revision ID: natalia.bidart@ubuntu.com-20151229234516-i822kgwc995ia2vk
Imported Django 1.8.7 from released tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
265
265
It boils down to this: Use exactly one of either ``configure()`` or
266
266
``DJANGO_SETTINGS_MODULE``. Not both, and not neither.
267
267
 
268
 
.. _@login_required: ../authentication/#the-login-required-decorator
 
268
Calling ``django.setup()`` is required for "standalone" Django usage
 
269
--------------------------------------------------------------------
 
270
 
 
271
If you're using components of Django "standalone" -- for example, writing a
 
272
Python script which loads some Django templates and renders them, or uses the
 
273
ORM to fetch some data -- there's one more step you'll need in addition to
 
274
configuring settings.
 
275
 
 
276
After you've either set :envvar:`DJANGO_SETTINGS_MODULE` or called
 
277
``configure()``, you'll need to call :func:`django.setup()` to load your
 
278
settings and populate Django's application registry. For example::
 
279
 
 
280
    import django
 
281
    from django.conf import settings
 
282
    from myapp import myapp_defaults
 
283
 
 
284
    settings.configure(default_settings=myapp_defaults, DEBUG=True)
 
285
    django.setup()
 
286
 
 
287
    # Now this script or any imported module can use any part of Django it needs.
 
288
    from myapp import models
 
289
 
 
290
Note that calling ``django.setup()`` is only necessary if your code is truly
 
291
standalone. When invoked by your Web server, or through :doc:`django-admin
 
292
</ref/django-admin>`, Django will handle this for you.
269
293
 
270
294
.. seealso::
271
295