summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-30 15:42:15 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-30 22:11:17 +0100
commit80d74097b4bd7186ad99b6d41d0ed90347a39b21 (patch)
tree7b00c5113c311aaaeba4393701151e916ae7f9f0 /docs
parent7ed20e015335076fc98ad805eaf241f8a0d872d5 (diff)
Stopped populating the app registry as a side effect.
Since it triggers imports, it shouldn't be done lightly. This commit adds a public API for doing it explicitly, django.setup(), and does it automatically when using manage.py and wsgi.py.
Diffstat (limited to 'docs')
-rw-r--r--docs/intro/tutorial01.txt16
-rw-r--r--docs/ref/django-admin.txt6
-rw-r--r--docs/releases/1.7.txt9
3 files changed, 28 insertions, 3 deletions
diff --git a/docs/intro/tutorial01.txt b/docs/intro/tutorial01.txt
index 4382f21a0f..0bd3d0abaf 100644
--- a/docs/intro/tutorial01.txt
+++ b/docs/intro/tutorial01.txt
@@ -602,9 +602,19 @@ the Python import path to your :file:`mysite/settings.py` file.
.. admonition:: Bypassing manage.py
If you'd rather not use :file:`manage.py`, no problem. Just set the
- ``DJANGO_SETTINGS_MODULE`` environment variable to ``mysite.settings`` and
- run ``python`` from the same directory :file:`manage.py` is in (or ensure
- that directory is on the Python path, so that ``import mysite`` works).
+ :envvar:`DJANGO_SETTINGS_MODULE` environment variable to
+ ``mysite.settings``, start a plain Python shell, and set up Django::
+
+ >>> import django
+ >>> django.setup()
+
+ If this raises an :exc:`~exceptions.AttributeError`, you're probably using
+ a version of Django that doesn't match this tutorial version. You'll want
+ to either switch to the older tutorial or the newer Django version.
+
+ You must run ``python`` from the same directory :file:`manage.py` is in,
+ or ensure that directory is on the Python path, so that ``import mysite``
+ works.
For more information on all of this, see the :doc:`django-admin.py
documentation </ref/django-admin>`.
diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
index 97923011f0..06f589ee63 100644
--- a/docs/ref/django-admin.txt
+++ b/docs/ref/django-admin.txt
@@ -14,6 +14,12 @@ two things for you before delegating to ``django-admin.py``:
* It sets the :envvar:`DJANGO_SETTINGS_MODULE` environment variable so that
it points to your project's ``settings.py`` file.
+* It calls ``django.setup()`` to initialize various internals of Django.
+
+.. versionadded:: 1.7
+
+ ``django.setup()`` didn't exist in previous versions of Django.
+
The ``django-admin.py`` script should be on your system path if you installed
Django via its ``setup.py`` utility. If it's not on your path, you can find it
in ``site-packages/django/bin`` within your Python installation. Consider
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
index b4ee180c73..87fa419188 100644
--- a/docs/releases/1.7.txt
+++ b/docs/releases/1.7.txt
@@ -613,6 +613,15 @@ Since :setting:`INSTALLED_APPS` now supports application configuration classes
in addition to application modules, you should review code that accesses this
setting directly and use the app registry (:attr:`django.apps.apps`) instead.
+If you're using Django in a plain Python script (not a management command) and
+rely on the :envvar:`DJANGO_SETTINGS_MODULE` environment variable, you must
+now explicitly initialize Django at the beginning of your script with::
+
+ >>> import django
+ >>> django.setup()
+
+Otherwise, you will most likely encounter a :exc:`~exceptions.RuntimeError`.
+
The "app registry" that manages the list of installed applications doesn't
have the same features as the old "app cache". Even though the "app cache" was
a private API, obsolete methods and arguments will be removed after a standard