2005-07-17 00:54:15 +00:00
|
|
|
=====================================
|
|
|
|
Writing your first Django app, part 2
|
|
|
|
=====================================
|
|
|
|
|
2010-08-19 19:27:44 +00:00
|
|
|
This tutorial begins where :doc:`Tutorial 1 </intro/tutorial01>` left off. We're
|
2008-08-23 22:25:40 +00:00
|
|
|
continuing the Web-poll application and will focus on Django's
|
|
|
|
automatically-generated admin site.
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2005-07-20 20:10:35 +00:00
|
|
|
.. admonition:: Philosophy
|
2005-07-21 02:17:45 +00:00
|
|
|
|
2005-07-20 20:10:35 +00:00
|
|
|
Generating admin sites for your staff or clients to add, change and delete
|
2008-08-23 22:25:40 +00:00
|
|
|
content is tedious work that doesn't require much creativity. For that
|
|
|
|
reason, Django entirely automates creation of admin interfaces for models.
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2005-07-20 20:10:35 +00:00
|
|
|
Django was written in a newsroom environment, with a very clear separation
|
|
|
|
between "content publishers" and the "public" site. Site managers use the
|
|
|
|
system to add news stories, events, sports scores, etc., and that content is
|
2008-08-23 22:25:40 +00:00
|
|
|
displayed on the public site. Django solves the problem of creating a
|
|
|
|
unified interface for site administrators to edit content.
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2012-03-02 17:16:52 +00:00
|
|
|
The admin isn't intended to be used by site visitors. It's for site
|
2012-02-26 21:17:58 +00:00
|
|
|
managers.
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2014-06-10 16:22:07 +00:00
|
|
|
Creating an admin user
|
|
|
|
======================
|
|
|
|
|
|
|
|
First we'll need to create a user who can login to the admin site. Run the
|
|
|
|
following command:
|
|
|
|
|
2015-02-19 03:19:21 +00:00
|
|
|
.. code-block:: console
|
2014-06-10 16:22:07 +00:00
|
|
|
|
|
|
|
$ python manage.py createsuperuser
|
|
|
|
|
|
|
|
Enter your desired username and press enter.
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
Username: admin
|
|
|
|
|
|
|
|
You will then be prompted for your desired email address:
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
Email address: admin@example.com
|
|
|
|
|
|
|
|
The final step is to enter your password. You will be asked to enter your
|
|
|
|
password twice, the second time as a confirmation of the first.
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
Password: **********
|
|
|
|
Password (again): *********
|
|
|
|
Superuser created successfully.
|
|
|
|
|
2005-07-18 23:14:48 +00:00
|
|
|
Start the development server
|
2005-07-17 00:54:15 +00:00
|
|
|
============================
|
|
|
|
|
Simplified default project template.
Squashed commit of:
commit 508ec9144b35c50794708225b496bde1eb5e60aa
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 22:50:55 2013 +0100
Tweaked default settings file.
* Explained why BASE_DIR exists.
* Added a link to the database configuration options, and put it in its
own section.
* Moved sensitive settings that must be changed for production at the
top.
commit 6515fd2f1aa73a86dc8dbd2ccf512ddb6b140d57
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 14:35:21 2013 +0100
Documented the simplified app & project templates in the changelog.
commit 2c5b576c2ea91d84273a019b3d0b3b8b4da72f23
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:59:27 2013 +0100
Minor fixes in tutorials 5 and 6.
commit 55a51531be8104f21b3cca3f6bf70b0a7139a041
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:51:11 2013 +0100
Updated tutorial 2 for the new project template.
commit 29ddae87bdaecff12dd31b16b000c01efbde9e20
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:58:54 2013 +0100
Updated tutorial 1 for the new project template.
commit 0ecb9f6e2514cfd26a678a280d471433375101a3
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:29:13 2013 +0100
Adjusted the default URLconf detection to account for the admin.
It's now enabled by default.
commit 5fb4da0d3d09dac28dd94e3fde92b9d4335c0565
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 10:36:55 2013 +0100
Added security warnings for the most sensitive settings.
commit 718d84bd8ac4a42fb4b28ec93965de32680f091e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:24:06 2013 +0100
Used an absolute path for the SQLite database.
This ensures the settings file works regardless of which directory
django-admin.py / manage.py is invoked from.
BASE_DIR got a +1 from a BDFL and another core dev. It doesn't involve
the concept of a "Django project"; it's just a convenient way to express
relative paths within the source code repository for non-Python files.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 1b559b4bcda622e10909b68fe5cab90db6727dd9
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:22:40 2013 +0100
Removed STATIC_ROOT from the default settings template.
It isn't necessary in development, and it confuses beginners to no end.
Thanks Carl Meyer for the suggestion.
commit a55f141a500bb7c9a1bc259bbe1954c13b199671
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:21:43 2013 +0100
Removed MEDIA_ROOT/URL from default settings template.
Many sites will never deal with user-uploaded files, and MEDIA_ROOT is
complicated to explain.
Thanks Carl Meyer for the suggestion.
commit 44bf2f2441420fd9429ee9fe1f7207f92dd87e70
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:22:09 2013 +0100
Removed logging config.
This configuration is applied regardless of the value of LOGGING;
duplicating it in LOGGING is confusing.
commit eac747e848eaed65fd5f6f254f0a7559d856f88f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:05:31 2013 +0100
Enabled the locale middleware by default.
USE_I18N is True by default, and doesn't work well without
LocaleMiddleware.
commit d806c62b2d00826dc2688c84b092627b8d571cab
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:03:16 2013 +0100
Enabled clickjacking protection by default.
commit 99152c30e6a15003f0b6737dc78e87adf462aacb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:01:48 2013 +0100
Reorganized settings in logical sections, and trimmed comments.
commit d37ffdfcb24b7e0ec7cc113d07190f65fb12fb8a
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:54:11 2013 +0100
Avoided misleading TEMPLATE_DEBUG = DEBUG.
According to the docs TEMPLATE_DEBUG works only when DEBUG = True.
commit 15d9478d3a9850e85841e7cf09cf83050371c6bf
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:46:25 2013 +0100
Removed STATICFILES_FINDERS/TEMPLATE_LOADERS from default settings file.
Only developers with special needs ever need to change these settings.
commit 574da0eb5bfb4570883756914b4dbd7e20e1f61e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:45:01 2013 +0100
Removed STATICFILES/TEMPLATES_DIRS from default settings file.
The current best practice is to put static files and templates in
applications, for easier testing and deployment.
commit 8cb18dbe56629aa1be74718a07e7cc66b4f9c9f0
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:24:16 2013 +0100
Removed settings related to email reporting from default settings file.
While handy for small scale projects, it isn't exactly a best practice.
commit 8ecbfcb3638058f0c49922540f874a7d802d864f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 18:54:43 2013 +0100
Documented how to enable the sites framework.
commit 23fc91a6fa67d91ddd9d71b1c3e0dc26bdad9841
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:28:59 2013 +0100
Disabled the sites framework by default.
RequestSite does the job for single-domain websites.
commit c4d82eb8afc0eb8568bf9c4d12644272415e3960
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 00:08:33 2013 +0100
Added a default admin.py to the application template.
Thanks Ryan D Hiebert for the suggestion.
commit 4071dc771e5c44b1c5ebb9beecefb164ae465e22
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:59:49 2013 +0100
Enabled the admin by default.
Everyone uses the admin.
commit c807a31f8d89e7e7fd97380e3023f7983a8b6fcb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:57:05 2013 +0100
Removed admindocs from default project template.
commit 09e4ce0e652a97da1a9e285046a91c8ad7a9189c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:32:52 2013 +0100
Added links to the settings documentation.
commit 5b8f5eaef364eb790fcde6f9e86f7d266074cca8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 11:06:54 2013 +0100
Used a significant example for URLconf includes.
commit 908e91d6fcee2a3cb51ca26ecdf12a6a24e69ef8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:22:31 2013 +0100
Moved code comments about WSGI to docs, and rewrote said docs.
commit 50417e51996146f891d08ca8b74dcc736a581932
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 15:51:50 2013 +0100
Normalized the default application template.
Removed the default test that 1 + 1 = 2, because it's been committed
way too many times, in too many projects.
Added an import of `render` for views, because the first view will
often be:
def home(request):
return render(request, "mysite/home.html")
2013-01-28 14:51:50 +00:00
|
|
|
The Django admin site is activated by default. Let's start the development
|
|
|
|
server and explore it.
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
Recall from Tutorial 1 that you start the development server like so:
|
|
|
|
|
2015-02-19 03:19:21 +00:00
|
|
|
.. code-block:: console
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2013-09-18 14:35:41 +00:00
|
|
|
$ python manage.py runserver
|
2005-07-18 23:22:07 +00:00
|
|
|
|
2005-10-19 01:09:05 +00:00
|
|
|
Now, open a Web browser and go to "/admin/" on your local domain -- e.g.,
|
|
|
|
http://127.0.0.1:8000/admin/. You should see the admin's login screen:
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin01.png
|
2005-07-17 00:54:15 +00:00
|
|
|
:alt: Django admin login screen
|
|
|
|
|
Simplified default project template.
Squashed commit of:
commit 508ec9144b35c50794708225b496bde1eb5e60aa
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 22:50:55 2013 +0100
Tweaked default settings file.
* Explained why BASE_DIR exists.
* Added a link to the database configuration options, and put it in its
own section.
* Moved sensitive settings that must be changed for production at the
top.
commit 6515fd2f1aa73a86dc8dbd2ccf512ddb6b140d57
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 14:35:21 2013 +0100
Documented the simplified app & project templates in the changelog.
commit 2c5b576c2ea91d84273a019b3d0b3b8b4da72f23
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:59:27 2013 +0100
Minor fixes in tutorials 5 and 6.
commit 55a51531be8104f21b3cca3f6bf70b0a7139a041
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:51:11 2013 +0100
Updated tutorial 2 for the new project template.
commit 29ddae87bdaecff12dd31b16b000c01efbde9e20
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:58:54 2013 +0100
Updated tutorial 1 for the new project template.
commit 0ecb9f6e2514cfd26a678a280d471433375101a3
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:29:13 2013 +0100
Adjusted the default URLconf detection to account for the admin.
It's now enabled by default.
commit 5fb4da0d3d09dac28dd94e3fde92b9d4335c0565
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 10:36:55 2013 +0100
Added security warnings for the most sensitive settings.
commit 718d84bd8ac4a42fb4b28ec93965de32680f091e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:24:06 2013 +0100
Used an absolute path for the SQLite database.
This ensures the settings file works regardless of which directory
django-admin.py / manage.py is invoked from.
BASE_DIR got a +1 from a BDFL and another core dev. It doesn't involve
the concept of a "Django project"; it's just a convenient way to express
relative paths within the source code repository for non-Python files.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 1b559b4bcda622e10909b68fe5cab90db6727dd9
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:22:40 2013 +0100
Removed STATIC_ROOT from the default settings template.
It isn't necessary in development, and it confuses beginners to no end.
Thanks Carl Meyer for the suggestion.
commit a55f141a500bb7c9a1bc259bbe1954c13b199671
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:21:43 2013 +0100
Removed MEDIA_ROOT/URL from default settings template.
Many sites will never deal with user-uploaded files, and MEDIA_ROOT is
complicated to explain.
Thanks Carl Meyer for the suggestion.
commit 44bf2f2441420fd9429ee9fe1f7207f92dd87e70
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:22:09 2013 +0100
Removed logging config.
This configuration is applied regardless of the value of LOGGING;
duplicating it in LOGGING is confusing.
commit eac747e848eaed65fd5f6f254f0a7559d856f88f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:05:31 2013 +0100
Enabled the locale middleware by default.
USE_I18N is True by default, and doesn't work well without
LocaleMiddleware.
commit d806c62b2d00826dc2688c84b092627b8d571cab
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:03:16 2013 +0100
Enabled clickjacking protection by default.
commit 99152c30e6a15003f0b6737dc78e87adf462aacb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:01:48 2013 +0100
Reorganized settings in logical sections, and trimmed comments.
commit d37ffdfcb24b7e0ec7cc113d07190f65fb12fb8a
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:54:11 2013 +0100
Avoided misleading TEMPLATE_DEBUG = DEBUG.
According to the docs TEMPLATE_DEBUG works only when DEBUG = True.
commit 15d9478d3a9850e85841e7cf09cf83050371c6bf
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:46:25 2013 +0100
Removed STATICFILES_FINDERS/TEMPLATE_LOADERS from default settings file.
Only developers with special needs ever need to change these settings.
commit 574da0eb5bfb4570883756914b4dbd7e20e1f61e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:45:01 2013 +0100
Removed STATICFILES/TEMPLATES_DIRS from default settings file.
The current best practice is to put static files and templates in
applications, for easier testing and deployment.
commit 8cb18dbe56629aa1be74718a07e7cc66b4f9c9f0
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:24:16 2013 +0100
Removed settings related to email reporting from default settings file.
While handy for small scale projects, it isn't exactly a best practice.
commit 8ecbfcb3638058f0c49922540f874a7d802d864f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 18:54:43 2013 +0100
Documented how to enable the sites framework.
commit 23fc91a6fa67d91ddd9d71b1c3e0dc26bdad9841
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:28:59 2013 +0100
Disabled the sites framework by default.
RequestSite does the job for single-domain websites.
commit c4d82eb8afc0eb8568bf9c4d12644272415e3960
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 00:08:33 2013 +0100
Added a default admin.py to the application template.
Thanks Ryan D Hiebert for the suggestion.
commit 4071dc771e5c44b1c5ebb9beecefb164ae465e22
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:59:49 2013 +0100
Enabled the admin by default.
Everyone uses the admin.
commit c807a31f8d89e7e7fd97380e3023f7983a8b6fcb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:57:05 2013 +0100
Removed admindocs from default project template.
commit 09e4ce0e652a97da1a9e285046a91c8ad7a9189c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:32:52 2013 +0100
Added links to the settings documentation.
commit 5b8f5eaef364eb790fcde6f9e86f7d266074cca8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 11:06:54 2013 +0100
Used a significant example for URLconf includes.
commit 908e91d6fcee2a3cb51ca26ecdf12a6a24e69ef8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:22:31 2013 +0100
Moved code comments about WSGI to docs, and rewrote said docs.
commit 50417e51996146f891d08ca8b74dcc736a581932
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 15:51:50 2013 +0100
Normalized the default application template.
Removed the default test that 1 + 1 = 2, because it's been committed
way too many times, in too many projects.
Added an import of `render` for views, because the first view will
often be:
def home(request):
return render(request, "mysite/home.html")
2013-01-28 14:51:50 +00:00
|
|
|
Since :doc:`translation </topics/i18n/translation>` is turned on by default,
|
|
|
|
the login screen may be displayed in your own language, depending on your
|
|
|
|
browser's settings and on whether Django has a translation for this language.
|
|
|
|
|
2011-10-13 11:21:42 +00:00
|
|
|
.. admonition:: Doesn't match what you see?
|
|
|
|
|
|
|
|
If at this point, instead of the above login page, you get an error
|
|
|
|
page reporting something like::
|
|
|
|
|
|
|
|
ImportError at /admin/
|
|
|
|
cannot import name patterns
|
|
|
|
...
|
|
|
|
|
|
|
|
then 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.
|
|
|
|
|
2005-07-17 00:54:15 +00:00
|
|
|
Enter the admin site
|
|
|
|
====================
|
|
|
|
|
2014-06-10 16:22:07 +00:00
|
|
|
Now, try logging in with the superuser account you created in the previous step.
|
Simplified default project template.
Squashed commit of:
commit 508ec9144b35c50794708225b496bde1eb5e60aa
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 22:50:55 2013 +0100
Tweaked default settings file.
* Explained why BASE_DIR exists.
* Added a link to the database configuration options, and put it in its
own section.
* Moved sensitive settings that must be changed for production at the
top.
commit 6515fd2f1aa73a86dc8dbd2ccf512ddb6b140d57
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 14:35:21 2013 +0100
Documented the simplified app & project templates in the changelog.
commit 2c5b576c2ea91d84273a019b3d0b3b8b4da72f23
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:59:27 2013 +0100
Minor fixes in tutorials 5 and 6.
commit 55a51531be8104f21b3cca3f6bf70b0a7139a041
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:51:11 2013 +0100
Updated tutorial 2 for the new project template.
commit 29ddae87bdaecff12dd31b16b000c01efbde9e20
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:58:54 2013 +0100
Updated tutorial 1 for the new project template.
commit 0ecb9f6e2514cfd26a678a280d471433375101a3
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:29:13 2013 +0100
Adjusted the default URLconf detection to account for the admin.
It's now enabled by default.
commit 5fb4da0d3d09dac28dd94e3fde92b9d4335c0565
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 10:36:55 2013 +0100
Added security warnings for the most sensitive settings.
commit 718d84bd8ac4a42fb4b28ec93965de32680f091e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:24:06 2013 +0100
Used an absolute path for the SQLite database.
This ensures the settings file works regardless of which directory
django-admin.py / manage.py is invoked from.
BASE_DIR got a +1 from a BDFL and another core dev. It doesn't involve
the concept of a "Django project"; it's just a convenient way to express
relative paths within the source code repository for non-Python files.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 1b559b4bcda622e10909b68fe5cab90db6727dd9
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:22:40 2013 +0100
Removed STATIC_ROOT from the default settings template.
It isn't necessary in development, and it confuses beginners to no end.
Thanks Carl Meyer for the suggestion.
commit a55f141a500bb7c9a1bc259bbe1954c13b199671
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:21:43 2013 +0100
Removed MEDIA_ROOT/URL from default settings template.
Many sites will never deal with user-uploaded files, and MEDIA_ROOT is
complicated to explain.
Thanks Carl Meyer for the suggestion.
commit 44bf2f2441420fd9429ee9fe1f7207f92dd87e70
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:22:09 2013 +0100
Removed logging config.
This configuration is applied regardless of the value of LOGGING;
duplicating it in LOGGING is confusing.
commit eac747e848eaed65fd5f6f254f0a7559d856f88f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:05:31 2013 +0100
Enabled the locale middleware by default.
USE_I18N is True by default, and doesn't work well without
LocaleMiddleware.
commit d806c62b2d00826dc2688c84b092627b8d571cab
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:03:16 2013 +0100
Enabled clickjacking protection by default.
commit 99152c30e6a15003f0b6737dc78e87adf462aacb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:01:48 2013 +0100
Reorganized settings in logical sections, and trimmed comments.
commit d37ffdfcb24b7e0ec7cc113d07190f65fb12fb8a
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:54:11 2013 +0100
Avoided misleading TEMPLATE_DEBUG = DEBUG.
According to the docs TEMPLATE_DEBUG works only when DEBUG = True.
commit 15d9478d3a9850e85841e7cf09cf83050371c6bf
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:46:25 2013 +0100
Removed STATICFILES_FINDERS/TEMPLATE_LOADERS from default settings file.
Only developers with special needs ever need to change these settings.
commit 574da0eb5bfb4570883756914b4dbd7e20e1f61e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:45:01 2013 +0100
Removed STATICFILES/TEMPLATES_DIRS from default settings file.
The current best practice is to put static files and templates in
applications, for easier testing and deployment.
commit 8cb18dbe56629aa1be74718a07e7cc66b4f9c9f0
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:24:16 2013 +0100
Removed settings related to email reporting from default settings file.
While handy for small scale projects, it isn't exactly a best practice.
commit 8ecbfcb3638058f0c49922540f874a7d802d864f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 18:54:43 2013 +0100
Documented how to enable the sites framework.
commit 23fc91a6fa67d91ddd9d71b1c3e0dc26bdad9841
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:28:59 2013 +0100
Disabled the sites framework by default.
RequestSite does the job for single-domain websites.
commit c4d82eb8afc0eb8568bf9c4d12644272415e3960
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 00:08:33 2013 +0100
Added a default admin.py to the application template.
Thanks Ryan D Hiebert for the suggestion.
commit 4071dc771e5c44b1c5ebb9beecefb164ae465e22
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:59:49 2013 +0100
Enabled the admin by default.
Everyone uses the admin.
commit c807a31f8d89e7e7fd97380e3023f7983a8b6fcb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:57:05 2013 +0100
Removed admindocs from default project template.
commit 09e4ce0e652a97da1a9e285046a91c8ad7a9189c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:32:52 2013 +0100
Added links to the settings documentation.
commit 5b8f5eaef364eb790fcde6f9e86f7d266074cca8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 11:06:54 2013 +0100
Used a significant example for URLconf includes.
commit 908e91d6fcee2a3cb51ca26ecdf12a6a24e69ef8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:22:31 2013 +0100
Moved code comments about WSGI to docs, and rewrote said docs.
commit 50417e51996146f891d08ca8b74dcc736a581932
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 15:51:50 2013 +0100
Normalized the default application template.
Removed the default test that 1 + 1 = 2, because it's been committed
way too many times, in too many projects.
Added an import of `render` for views, because the first view will
often be:
def home(request):
return render(request, "mysite/home.html")
2013-01-28 14:51:50 +00:00
|
|
|
You should see the Django admin index page:
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
.. image:: _images/admin02.png
|
2005-07-17 00:54:15 +00:00
|
|
|
:alt: Django admin index page
|
|
|
|
|
Simplified default project template.
Squashed commit of:
commit 508ec9144b35c50794708225b496bde1eb5e60aa
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 22:50:55 2013 +0100
Tweaked default settings file.
* Explained why BASE_DIR exists.
* Added a link to the database configuration options, and put it in its
own section.
* Moved sensitive settings that must be changed for production at the
top.
commit 6515fd2f1aa73a86dc8dbd2ccf512ddb6b140d57
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 14:35:21 2013 +0100
Documented the simplified app & project templates in the changelog.
commit 2c5b576c2ea91d84273a019b3d0b3b8b4da72f23
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:59:27 2013 +0100
Minor fixes in tutorials 5 and 6.
commit 55a51531be8104f21b3cca3f6bf70b0a7139a041
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:51:11 2013 +0100
Updated tutorial 2 for the new project template.
commit 29ddae87bdaecff12dd31b16b000c01efbde9e20
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:58:54 2013 +0100
Updated tutorial 1 for the new project template.
commit 0ecb9f6e2514cfd26a678a280d471433375101a3
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:29:13 2013 +0100
Adjusted the default URLconf detection to account for the admin.
It's now enabled by default.
commit 5fb4da0d3d09dac28dd94e3fde92b9d4335c0565
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 10:36:55 2013 +0100
Added security warnings for the most sensitive settings.
commit 718d84bd8ac4a42fb4b28ec93965de32680f091e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:24:06 2013 +0100
Used an absolute path for the SQLite database.
This ensures the settings file works regardless of which directory
django-admin.py / manage.py is invoked from.
BASE_DIR got a +1 from a BDFL and another core dev. It doesn't involve
the concept of a "Django project"; it's just a convenient way to express
relative paths within the source code repository for non-Python files.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 1b559b4bcda622e10909b68fe5cab90db6727dd9
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:22:40 2013 +0100
Removed STATIC_ROOT from the default settings template.
It isn't necessary in development, and it confuses beginners to no end.
Thanks Carl Meyer for the suggestion.
commit a55f141a500bb7c9a1bc259bbe1954c13b199671
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:21:43 2013 +0100
Removed MEDIA_ROOT/URL from default settings template.
Many sites will never deal with user-uploaded files, and MEDIA_ROOT is
complicated to explain.
Thanks Carl Meyer for the suggestion.
commit 44bf2f2441420fd9429ee9fe1f7207f92dd87e70
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:22:09 2013 +0100
Removed logging config.
This configuration is applied regardless of the value of LOGGING;
duplicating it in LOGGING is confusing.
commit eac747e848eaed65fd5f6f254f0a7559d856f88f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:05:31 2013 +0100
Enabled the locale middleware by default.
USE_I18N is True by default, and doesn't work well without
LocaleMiddleware.
commit d806c62b2d00826dc2688c84b092627b8d571cab
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:03:16 2013 +0100
Enabled clickjacking protection by default.
commit 99152c30e6a15003f0b6737dc78e87adf462aacb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:01:48 2013 +0100
Reorganized settings in logical sections, and trimmed comments.
commit d37ffdfcb24b7e0ec7cc113d07190f65fb12fb8a
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:54:11 2013 +0100
Avoided misleading TEMPLATE_DEBUG = DEBUG.
According to the docs TEMPLATE_DEBUG works only when DEBUG = True.
commit 15d9478d3a9850e85841e7cf09cf83050371c6bf
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:46:25 2013 +0100
Removed STATICFILES_FINDERS/TEMPLATE_LOADERS from default settings file.
Only developers with special needs ever need to change these settings.
commit 574da0eb5bfb4570883756914b4dbd7e20e1f61e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:45:01 2013 +0100
Removed STATICFILES/TEMPLATES_DIRS from default settings file.
The current best practice is to put static files and templates in
applications, for easier testing and deployment.
commit 8cb18dbe56629aa1be74718a07e7cc66b4f9c9f0
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:24:16 2013 +0100
Removed settings related to email reporting from default settings file.
While handy for small scale projects, it isn't exactly a best practice.
commit 8ecbfcb3638058f0c49922540f874a7d802d864f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 18:54:43 2013 +0100
Documented how to enable the sites framework.
commit 23fc91a6fa67d91ddd9d71b1c3e0dc26bdad9841
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:28:59 2013 +0100
Disabled the sites framework by default.
RequestSite does the job for single-domain websites.
commit c4d82eb8afc0eb8568bf9c4d12644272415e3960
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 00:08:33 2013 +0100
Added a default admin.py to the application template.
Thanks Ryan D Hiebert for the suggestion.
commit 4071dc771e5c44b1c5ebb9beecefb164ae465e22
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:59:49 2013 +0100
Enabled the admin by default.
Everyone uses the admin.
commit c807a31f8d89e7e7fd97380e3023f7983a8b6fcb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:57:05 2013 +0100
Removed admindocs from default project template.
commit 09e4ce0e652a97da1a9e285046a91c8ad7a9189c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:32:52 2013 +0100
Added links to the settings documentation.
commit 5b8f5eaef364eb790fcde6f9e86f7d266074cca8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 11:06:54 2013 +0100
Used a significant example for URLconf includes.
commit 908e91d6fcee2a3cb51ca26ecdf12a6a24e69ef8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:22:31 2013 +0100
Moved code comments about WSGI to docs, and rewrote said docs.
commit 50417e51996146f891d08ca8b74dcc736a581932
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 15:51:50 2013 +0100
Normalized the default application template.
Removed the default test that 1 + 1 = 2, because it's been committed
way too many times, in too many projects.
Added an import of `render` for views, because the first view will
often be:
def home(request):
return render(request, "mysite/home.html")
2013-01-28 14:51:50 +00:00
|
|
|
You should see a few types of editable content: groups and users. They are
|
|
|
|
provided by :mod:`django.contrib.auth`, the authentication framework shipped
|
|
|
|
by Django.
|
2005-07-17 00:54:15 +00:00
|
|
|
|
|
|
|
Make the poll app modifiable in the admin
|
|
|
|
=========================================
|
|
|
|
|
|
|
|
But where's our poll app? It's not displayed on the admin index page.
|
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Just one thing to do: we need to tell the admin that ``Question``
|
2013-04-12 23:22:02 +00:00
|
|
|
objects have an admin interface. To do this, open the :file:`polls/admin.py`
|
2013-09-23 22:23:47 +00:00
|
|
|
file, and edit it to look like this:
|
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
from django.contrib import admin
|
2015-02-22 14:59:56 +00:00
|
|
|
|
|
|
|
from .models import Question
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
admin.site.register(Question)
|
2005-07-17 00:54:15 +00:00
|
|
|
|
|
|
|
Explore the free admin functionality
|
|
|
|
====================================
|
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Now that we've registered ``Question``, Django knows that it should be displayed on
|
2008-07-18 23:54:34 +00:00
|
|
|
the admin index page:
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin03t.png
|
2005-07-17 00:54:15 +00:00
|
|
|
:alt: Django admin index page, now with polls displayed
|
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Click "Questions". Now you're at the "change list" page for questions. This page
|
|
|
|
displays all the question in the database and lets you choose one to change it.
|
|
|
|
There's the "What's up?" question we created in the first tutorial:
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin04t.png
|
2005-07-17 00:54:15 +00:00
|
|
|
:alt: Polls change list page
|
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Click the "What's up?" question to edit it:
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin05t.png
|
2013-09-06 18:57:00 +00:00
|
|
|
:alt: Editing form for question object
|
2005-07-17 00:54:15 +00:00
|
|
|
|
|
|
|
Things to note here:
|
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
* The form is automatically generated from the ``Question`` model.
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2011-10-14 00:12:01 +00:00
|
|
|
* The different model field types (:class:`~django.db.models.DateTimeField`,
|
|
|
|
:class:`~django.db.models.CharField`) correspond to the appropriate HTML
|
|
|
|
input widget. Each type of field knows how to display itself in the Django
|
|
|
|
admin.
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2011-10-14 00:12:01 +00:00
|
|
|
* Each :class:`~django.db.models.DateTimeField` gets free JavaScript
|
|
|
|
shortcuts. Dates get a "Today" shortcut and calendar popup, and times get
|
|
|
|
a "Now" shortcut and a convenient popup that lists commonly entered times.
|
2005-07-17 01:00:25 +00:00
|
|
|
|
|
|
|
The bottom part of the page gives you a couple of options:
|
|
|
|
|
2011-10-14 00:12:01 +00:00
|
|
|
* Save -- Saves changes and returns to the change-list page for this type of
|
|
|
|
object.
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2011-10-14 00:12:01 +00:00
|
|
|
* Save and continue editing -- Saves changes and reloads the admin page for
|
|
|
|
this object.
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2011-10-14 00:12:01 +00:00
|
|
|
* Save and add another -- Saves changes and loads a new, blank form for this
|
|
|
|
type of object.
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2011-10-14 00:12:01 +00:00
|
|
|
* Delete -- Displays a delete confirmation page.
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2012-02-26 21:17:58 +00:00
|
|
|
If the value of "Date published" doesn't match the time when you created the
|
2013-09-06 18:57:00 +00:00
|
|
|
question in Tutorial 1, it probably means you forgot to set the correct value for
|
2012-03-02 17:16:52 +00:00
|
|
|
the :setting:`TIME_ZONE` setting. Change it, reload the page and check that
|
2012-02-26 21:17:58 +00:00
|
|
|
the correct value appears.
|
|
|
|
|
2005-07-17 00:54:15 +00:00
|
|
|
Change the "Date published" by clicking the "Today" and "Now" shortcuts. Then
|
|
|
|
click "Save and continue editing." Then click "History" in the upper right.
|
|
|
|
You'll see a page listing all changes made to this object via the Django admin,
|
|
|
|
with the timestamp and username of the person who made the change:
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin06t.png
|
2013-09-06 18:57:00 +00:00
|
|
|
:alt: History page for question object
|
2005-07-17 00:54:15 +00:00
|
|
|
|
|
|
|
Customize the admin form
|
|
|
|
========================
|
|
|
|
|
Fixed #10389, #10501, #10502, #10540, #10562, #10563, #10564, #10565, #10568, #10569, #10614, #10617, #10619 -- Fixed several typos as well as a couple minor issues in the docs, patches from timo, nih, bthomas, rduffield, UloPe, and sebleier@gmail.com.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10242 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-31 07:01:01 +00:00
|
|
|
Take a few minutes to marvel at all the code you didn't have to write. By
|
2013-09-06 18:57:00 +00:00
|
|
|
registering the ``Question`` model with ``admin.site.register(Question)``,
|
|
|
|
Django was able to construct a default form representation. Often, you'll want
|
|
|
|
to customize how the admin form looks and works. You'll do this by telling
|
|
|
|
Django the options you want when you register the object.
|
2005-07-17 00:54:15 +00:00
|
|
|
|
Fixed #10389, #10501, #10502, #10540, #10562, #10563, #10564, #10565, #10568, #10569, #10614, #10617, #10619 -- Fixed several typos as well as a couple minor issues in the docs, patches from timo, nih, bthomas, rduffield, UloPe, and sebleier@gmail.com.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10242 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-31 07:01:01 +00:00
|
|
|
Let's see how this works by re-ordering the fields on the edit form. Replace
|
2013-09-23 22:23:47 +00:00
|
|
|
the ``admin.site.register(Question)`` line with:
|
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2013-05-18 11:34:29 +00:00
|
|
|
from django.contrib import admin
|
2015-02-22 14:59:56 +00:00
|
|
|
|
|
|
|
from .models import Question
|
2013-05-18 11:34:29 +00:00
|
|
|
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
class QuestionAdmin(admin.ModelAdmin):
|
|
|
|
fields = ['pub_date', 'question_text']
|
|
|
|
|
|
|
|
admin.site.register(Question, QuestionAdmin)
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
You'll follow this pattern -- create a model admin object, then pass it as the
|
|
|
|
second argument to ``admin.site.register()`` -- any time you need to change the
|
|
|
|
admin options for an object.
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
This particular change above makes the "Publication date" come before the
|
|
|
|
"Question" field:
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin07.png
|
2005-07-17 00:54:15 +00:00
|
|
|
:alt: Fields have been reordered
|
|
|
|
|
|
|
|
This isn't impressive with only two fields, but for admin forms with dozens
|
|
|
|
of fields, choosing an intuitive order is an important usability detail.
|
|
|
|
|
|
|
|
And speaking of forms with dozens of fields, you might want to split the form
|
2013-09-23 22:23:47 +00:00
|
|
|
up into fieldsets:
|
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2013-05-18 11:34:29 +00:00
|
|
|
from django.contrib import admin
|
2015-02-22 14:59:56 +00:00
|
|
|
|
|
|
|
from .models import Question
|
2013-09-06 18:57:00 +00:00
|
|
|
|
2013-05-18 11:34:29 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
class QuestionAdmin(admin.ModelAdmin):
|
2008-07-18 23:54:34 +00:00
|
|
|
fieldsets = [
|
2013-09-06 18:57:00 +00:00
|
|
|
(None, {'fields': ['question_text']}),
|
2008-07-18 23:54:34 +00:00
|
|
|
('Date information', {'fields': ['pub_date']}),
|
|
|
|
]
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
admin.site.register(Question, QuestionAdmin)
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2014-04-30 22:22:43 +00:00
|
|
|
The first element of each tuple in
|
|
|
|
:attr:`~django.contrib.admin.ModelAdmin.fieldsets` is the title of the fieldset.
|
2005-07-17 00:54:15 +00:00
|
|
|
Here's what our form looks like now:
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin08t.png
|
2005-07-17 00:54:15 +00:00
|
|
|
:alt: Form has fieldsets now
|
|
|
|
|
|
|
|
You can assign arbitrary HTML classes to each fieldset. Django provides a
|
|
|
|
``"collapse"`` class that displays a particular fieldset initially collapsed.
|
|
|
|
This is useful when you have a long form that contains a number of fields that
|
2013-09-23 22:23:47 +00:00
|
|
|
aren't commonly used:
|
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2013-10-22 09:19:38 +00:00
|
|
|
from django.contrib import admin
|
2015-02-22 14:59:56 +00:00
|
|
|
|
|
|
|
from .models import Question
|
2013-09-06 18:57:00 +00:00
|
|
|
|
2013-05-18 11:34:29 +00:00
|
|
|
|
2013-10-22 09:19:38 +00:00
|
|
|
class QuestionAdmin(admin.ModelAdmin):
|
|
|
|
fieldsets = [
|
|
|
|
(None, {'fields': ['question_text']}),
|
|
|
|
('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
|
|
|
|
]
|
2005-07-17 00:54:15 +00:00
|
|
|
|
2014-11-24 20:58:56 +00:00
|
|
|
admin.site.register(Question, QuestionAdmin)
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin09.png
|
2005-07-17 00:54:15 +00:00
|
|
|
:alt: Fieldset is initially collapsed
|
|
|
|
|
2005-07-17 05:21:19 +00:00
|
|
|
Adding related objects
|
|
|
|
======================
|
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
OK, we have our Question admin page. But a ``Question`` has multiple ``Choices``, and
|
2006-01-11 02:06:27 +00:00
|
|
|
the admin page doesn't display choices.
|
2005-07-17 05:21:19 +00:00
|
|
|
|
|
|
|
Yet.
|
|
|
|
|
2009-06-18 13:32:12 +00:00
|
|
|
There are two ways to solve this problem. The first is to register ``Choice``
|
2013-09-23 22:23:47 +00:00
|
|
|
with the admin just as we did with ``Question``. That's easy:
|
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2013-05-18 11:34:29 +00:00
|
|
|
from django.contrib import admin
|
2015-02-22 14:59:56 +00:00
|
|
|
|
|
|
|
from .models import Choice, Question
|
2014-08-02 01:32:53 +00:00
|
|
|
# ...
|
2008-07-18 23:54:34 +00:00
|
|
|
admin.site.register(Choice)
|
2005-07-17 05:21:19 +00:00
|
|
|
|
|
|
|
Now "Choices" is an available option in the Django admin. The "Add choice" form
|
2005-07-17 05:22:48 +00:00
|
|
|
looks like this:
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin10.png
|
2005-07-17 05:21:19 +00:00
|
|
|
:alt: Choice admin page
|
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
In that form, the "Question" field is a select box containing every question in the
|
2008-08-23 22:25:40 +00:00
|
|
|
database. Django knows that a :class:`~django.db.models.ForeignKey` should be
|
2013-09-06 18:57:00 +00:00
|
|
|
represented in the admin as a ``<select>`` box. In our case, only one question
|
2008-08-23 22:25:40 +00:00
|
|
|
exists at this point.
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Also note the "Add Another" link next to "Question." Every object with a
|
2008-07-18 23:54:34 +00:00
|
|
|
``ForeignKey`` relationship to another gets this for free. When you click "Add
|
2013-09-06 18:57:00 +00:00
|
|
|
Another," you'll get a popup window with the "Add question" form. If you add a question
|
|
|
|
in that window and click "Save," Django will save the question to the database and
|
2008-07-18 23:54:34 +00:00
|
|
|
dynamically add it as the selected choice on the "Add choice" form you're
|
|
|
|
looking at.
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2012-05-25 19:13:51 +00:00
|
|
|
But, really, this is an inefficient way of adding ``Choice`` objects to the system.
|
2005-07-17 05:21:19 +00:00
|
|
|
It'd be better if you could add a bunch of Choices directly when you create the
|
2013-09-06 18:57:00 +00:00
|
|
|
``Question`` object. Let's make that happen.
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Remove the ``register()`` call for the ``Choice`` model. Then, edit the ``Question``
|
2013-09-23 22:23:47 +00:00
|
|
|
registration code to read:
|
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2012-06-30 18:50:24 +00:00
|
|
|
from django.contrib import admin
|
2015-02-22 14:59:56 +00:00
|
|
|
|
|
|
|
from .models import Choice, Question
|
2013-09-06 18:57:00 +00:00
|
|
|
|
2012-06-30 18:50:24 +00:00
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
class ChoiceInline(admin.StackedInline):
|
|
|
|
model = Choice
|
|
|
|
extra = 3
|
2008-09-11 03:32:28 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
|
|
|
|
class QuestionAdmin(admin.ModelAdmin):
|
2008-07-18 23:54:34 +00:00
|
|
|
fieldsets = [
|
2013-09-06 18:57:00 +00:00
|
|
|
(None, {'fields': ['question_text']}),
|
2014-08-02 01:32:53 +00:00
|
|
|
('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
|
2008-07-18 23:54:34 +00:00
|
|
|
]
|
|
|
|
inlines = [ChoiceInline]
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
admin.site.register(Question, QuestionAdmin)
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
This tells Django: "``Choice`` objects are edited on the ``Question`` admin page. By
|
2008-07-18 23:54:34 +00:00
|
|
|
default, provide enough fields for 3 choices."
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Load the "Add question" page to see how that looks:
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin11t.png
|
2013-09-06 18:57:00 +00:00
|
|
|
:alt: Add question page now has choices on it
|
2005-07-17 05:21:19 +00:00
|
|
|
|
|
|
|
It works like this: There are three slots for related Choices -- as specified
|
2008-07-18 23:54:34 +00:00
|
|
|
by ``extra`` -- and each time you come back to the "Change" page for an
|
|
|
|
already-created object, you get another three extra slots.
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2012-08-02 23:21:48 +00:00
|
|
|
At the end of the three current slots you will find an "Add another Choice"
|
|
|
|
link. If you click on it, a new slot will be added. If you want to remove the
|
|
|
|
added slot, you can click on the X to the top right of the added slot. Note
|
|
|
|
that you can't remove the original three slots. This image shows an added slot:
|
|
|
|
|
|
|
|
.. image:: _images/admin15t.png
|
|
|
|
:alt: Additional slot added dynamically
|
|
|
|
|
2005-07-17 05:21:19 +00:00
|
|
|
One small problem, though. It takes a lot of screen space to display all the
|
2012-05-25 19:13:51 +00:00
|
|
|
fields for entering related ``Choice`` objects. For that reason, Django offers a
|
2008-07-18 23:54:34 +00:00
|
|
|
tabular way of displaying inline related objects; you just need to change
|
2013-09-23 22:23:47 +00:00
|
|
|
the ``ChoiceInline`` declaration to read:
|
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
class ChoiceInline(admin.TabularInline):
|
|
|
|
#...
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
With that ``TabularInline`` (instead of ``StackedInline``), the
|
2005-08-09 21:08:00 +00:00
|
|
|
related objects are displayed in a more compact, table-based format:
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2012-06-30 22:20:34 +00:00
|
|
|
.. image:: _images/admin12t.png
|
2013-09-06 18:57:00 +00:00
|
|
|
:alt: Add question page now has more compact choices
|
2005-07-17 05:21:19 +00:00
|
|
|
|
2012-06-30 22:20:34 +00:00
|
|
|
Note that there is an extra "Delete?" column that allows removing rows added
|
|
|
|
using the "Add Another Choice" button and rows that have already been saved.
|
|
|
|
|
2005-07-17 05:52:07 +00:00
|
|
|
Customize the admin change list
|
|
|
|
===============================
|
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Now that the Question admin page is looking good, let's make some tweaks to the
|
|
|
|
"change list" page -- the one that displays all the questions in the system.
|
2005-07-17 05:52:07 +00:00
|
|
|
|
|
|
|
Here's what it looks like at this point:
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin04t.png
|
2005-07-17 05:52:07 +00:00
|
|
|
:alt: Polls change list page
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
By default, Django displays the ``str()`` of each object. But sometimes it'd be
|
|
|
|
more helpful if we could display individual fields. To do that, use the
|
2014-04-30 22:22:43 +00:00
|
|
|
:attr:`~django.contrib.admin.ModelAdmin.list_display` admin option, which is a
|
|
|
|
tuple of field names to display, as columns, on the change list page for the
|
|
|
|
object:
|
2013-09-23 22:23:47 +00:00
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
class QuestionAdmin(admin.ModelAdmin):
|
2005-07-17 05:52:07 +00:00
|
|
|
# ...
|
2013-09-06 18:57:00 +00:00
|
|
|
list_display = ('question_text', 'pub_date')
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2012-02-26 21:17:58 +00:00
|
|
|
Just for good measure, let's also include the ``was_published_recently`` custom
|
2013-09-23 22:23:47 +00:00
|
|
|
method from Tutorial 1:
|
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: polls/admin.py
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
class QuestionAdmin(admin.ModelAdmin):
|
2008-07-18 23:54:34 +00:00
|
|
|
# ...
|
2013-09-06 18:57:00 +00:00
|
|
|
list_display = ('question_text', 'pub_date', 'was_published_recently')
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
Now the question change list page looks like this:
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin13t.png
|
2005-07-17 05:52:07 +00:00
|
|
|
:alt: Polls change list page, updated
|
|
|
|
|
|
|
|
You can click on the column headers to sort by those values -- except in the
|
2012-02-26 21:17:58 +00:00
|
|
|
case of the ``was_published_recently`` header, because sorting by the output
|
|
|
|
of an arbitrary method is not supported. Also note that the column header for
|
|
|
|
``was_published_recently`` is, by default, the name of the method (with
|
|
|
|
underscores replaced with spaces), and that each line contains the string
|
|
|
|
representation of the output.
|
|
|
|
|
2013-04-12 23:22:02 +00:00
|
|
|
You can improve that by giving that method (in :file:`polls/models.py`) a few
|
2013-09-23 22:23:47 +00:00
|
|
|
attributes, as follows:
|
|
|
|
|
|
|
|
.. snippet::
|
2013-11-10 11:10:13 +00:00
|
|
|
:filename: polls/models.py
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
class Question(models.Model):
|
2012-02-18 21:50:48 +00:00
|
|
|
# ...
|
2012-02-26 21:17:58 +00:00
|
|
|
def was_published_recently(self):
|
|
|
|
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
|
|
|
|
was_published_recently.admin_order_field = 'pub_date'
|
|
|
|
was_published_recently.boolean = True
|
|
|
|
was_published_recently.short_description = 'Published recently?'
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2014-11-13 17:16:20 +00:00
|
|
|
For more information on these method properties, see
|
|
|
|
:attr:`~django.contrib.admin.ModelAdmin.list_display`.
|
|
|
|
|
2014-04-30 22:22:43 +00:00
|
|
|
Edit your :file:`polls/admin.py` file again and add an improvement to the
|
|
|
|
``Question`` change list page: filters using the
|
|
|
|
:attr:`~django.contrib.admin.ModelAdmin.list_filter`. Add the following line to
|
|
|
|
``QuestionAdmin``::
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2006-05-02 01:31:56 +00:00
|
|
|
list_filter = ['pub_date']
|
2005-07-17 05:52:07 +00:00
|
|
|
|
|
|
|
That adds a "Filter" sidebar that lets people filter the change list by the
|
|
|
|
``pub_date`` field:
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
.. image:: _images/admin14t.png
|
2005-07-17 05:52:07 +00:00
|
|
|
:alt: Polls change list page, updated
|
|
|
|
|
|
|
|
The type of filter displayed depends on the type of field you're filtering on.
|
2012-12-25 14:56:22 +00:00
|
|
|
Because ``pub_date`` is a :class:`~django.db.models.DateTimeField`, Django
|
|
|
|
knows to give appropriate filter options: "Any date," "Today," "Past 7 days,"
|
|
|
|
"This month," "This year."
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2005-07-17 05:54:43 +00:00
|
|
|
This is shaping up well. Let's add some search capability::
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2013-09-06 18:57:00 +00:00
|
|
|
search_fields = ['question_text']
|
2005-07-17 05:52:07 +00:00
|
|
|
|
|
|
|
That adds a search box at the top of the change list. When somebody enters
|
2013-09-06 18:57:00 +00:00
|
|
|
search terms, Django will search the ``question_text`` field. You can use as many
|
2006-01-11 02:06:27 +00:00
|
|
|
fields as you'd like -- although because it uses a ``LIKE`` query behind the
|
2014-04-30 17:43:36 +00:00
|
|
|
scenes, limiting the number of search fields to a reasonable number will make
|
|
|
|
it easier for your database to do the search.
|
2005-07-17 05:52:07 +00:00
|
|
|
|
|
|
|
Now's also a good time to note that change lists give you free pagination. The
|
2014-04-30 22:22:43 +00:00
|
|
|
default is to display 100 items per page. :attr:`Change list pagination
|
|
|
|
<django.contrib.admin.ModelAdmin.list_per_page>`, :attr:`search boxes
|
|
|
|
<django.contrib.admin.ModelAdmin.search_fields>`, :attr:`filters
|
|
|
|
<django.contrib.admin.ModelAdmin.list_filter>`, :attr:`date-hierarchies
|
|
|
|
<django.contrib.admin.ModelAdmin.date_hierarchy>`, and
|
|
|
|
:attr:`column-header-ordering <django.contrib.admin.ModelAdmin.list_display>`
|
|
|
|
all work together like you think they should.
|
2005-07-17 05:52:07 +00:00
|
|
|
|
2005-07-17 06:11:33 +00:00
|
|
|
Customize the admin look and feel
|
|
|
|
=================================
|
|
|
|
|
2007-08-07 02:33:11 +00:00
|
|
|
Clearly, having "Django administration" at the top of each admin page is
|
|
|
|
ridiculous. It's just placeholder text.
|
2005-07-17 06:11:33 +00:00
|
|
|
|
2005-10-19 01:09:05 +00:00
|
|
|
That's easy to change, though, using Django's template system. The Django admin
|
|
|
|
is powered by Django itself, and its interfaces use Django's own template
|
2010-01-10 18:55:04 +00:00
|
|
|
system.
|
2005-07-17 06:11:33 +00:00
|
|
|
|
2013-02-07 10:51:25 +00:00
|
|
|
.. _ref-customizing-your-projects-templates:
|
|
|
|
|
|
|
|
Customizing your *project's* templates
|
|
|
|
--------------------------------------
|
|
|
|
|
2015-03-27 13:57:58 +00:00
|
|
|
Create a ``templates`` directory in your project directory (the one that
|
|
|
|
contains ``manage.py``). Templates can live anywhere on your filesystem that
|
|
|
|
Django can access. (Django runs as whatever user your server runs.) However,
|
|
|
|
keeping your templates within the project is a good convention to follow.
|
2012-10-13 18:37:39 +00:00
|
|
|
|
2013-04-12 23:22:02 +00:00
|
|
|
Open your settings file (:file:`mysite/settings.py`, remember) and add a
|
2014-12-17 21:51:42 +00:00
|
|
|
:setting:`DIRS <TEMPLATES-DIRS>` option in the :setting:`TEMPLATES` setting:
|
2013-09-23 22:23:47 +00:00
|
|
|
|
|
|
|
.. snippet::
|
|
|
|
:filename: mysite/settings.py
|
Simplified default project template.
Squashed commit of:
commit 508ec9144b35c50794708225b496bde1eb5e60aa
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 22:50:55 2013 +0100
Tweaked default settings file.
* Explained why BASE_DIR exists.
* Added a link to the database configuration options, and put it in its
own section.
* Moved sensitive settings that must be changed for production at the
top.
commit 6515fd2f1aa73a86dc8dbd2ccf512ddb6b140d57
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 14:35:21 2013 +0100
Documented the simplified app & project templates in the changelog.
commit 2c5b576c2ea91d84273a019b3d0b3b8b4da72f23
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:59:27 2013 +0100
Minor fixes in tutorials 5 and 6.
commit 55a51531be8104f21b3cca3f6bf70b0a7139a041
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:51:11 2013 +0100
Updated tutorial 2 for the new project template.
commit 29ddae87bdaecff12dd31b16b000c01efbde9e20
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:58:54 2013 +0100
Updated tutorial 1 for the new project template.
commit 0ecb9f6e2514cfd26a678a280d471433375101a3
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:29:13 2013 +0100
Adjusted the default URLconf detection to account for the admin.
It's now enabled by default.
commit 5fb4da0d3d09dac28dd94e3fde92b9d4335c0565
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 10:36:55 2013 +0100
Added security warnings for the most sensitive settings.
commit 718d84bd8ac4a42fb4b28ec93965de32680f091e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:24:06 2013 +0100
Used an absolute path for the SQLite database.
This ensures the settings file works regardless of which directory
django-admin.py / manage.py is invoked from.
BASE_DIR got a +1 from a BDFL and another core dev. It doesn't involve
the concept of a "Django project"; it's just a convenient way to express
relative paths within the source code repository for non-Python files.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 1b559b4bcda622e10909b68fe5cab90db6727dd9
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:22:40 2013 +0100
Removed STATIC_ROOT from the default settings template.
It isn't necessary in development, and it confuses beginners to no end.
Thanks Carl Meyer for the suggestion.
commit a55f141a500bb7c9a1bc259bbe1954c13b199671
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:21:43 2013 +0100
Removed MEDIA_ROOT/URL from default settings template.
Many sites will never deal with user-uploaded files, and MEDIA_ROOT is
complicated to explain.
Thanks Carl Meyer for the suggestion.
commit 44bf2f2441420fd9429ee9fe1f7207f92dd87e70
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:22:09 2013 +0100
Removed logging config.
This configuration is applied regardless of the value of LOGGING;
duplicating it in LOGGING is confusing.
commit eac747e848eaed65fd5f6f254f0a7559d856f88f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:05:31 2013 +0100
Enabled the locale middleware by default.
USE_I18N is True by default, and doesn't work well without
LocaleMiddleware.
commit d806c62b2d00826dc2688c84b092627b8d571cab
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:03:16 2013 +0100
Enabled clickjacking protection by default.
commit 99152c30e6a15003f0b6737dc78e87adf462aacb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:01:48 2013 +0100
Reorganized settings in logical sections, and trimmed comments.
commit d37ffdfcb24b7e0ec7cc113d07190f65fb12fb8a
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:54:11 2013 +0100
Avoided misleading TEMPLATE_DEBUG = DEBUG.
According to the docs TEMPLATE_DEBUG works only when DEBUG = True.
commit 15d9478d3a9850e85841e7cf09cf83050371c6bf
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:46:25 2013 +0100
Removed STATICFILES_FINDERS/TEMPLATE_LOADERS from default settings file.
Only developers with special needs ever need to change these settings.
commit 574da0eb5bfb4570883756914b4dbd7e20e1f61e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:45:01 2013 +0100
Removed STATICFILES/TEMPLATES_DIRS from default settings file.
The current best practice is to put static files and templates in
applications, for easier testing and deployment.
commit 8cb18dbe56629aa1be74718a07e7cc66b4f9c9f0
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:24:16 2013 +0100
Removed settings related to email reporting from default settings file.
While handy for small scale projects, it isn't exactly a best practice.
commit 8ecbfcb3638058f0c49922540f874a7d802d864f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 18:54:43 2013 +0100
Documented how to enable the sites framework.
commit 23fc91a6fa67d91ddd9d71b1c3e0dc26bdad9841
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:28:59 2013 +0100
Disabled the sites framework by default.
RequestSite does the job for single-domain websites.
commit c4d82eb8afc0eb8568bf9c4d12644272415e3960
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 00:08:33 2013 +0100
Added a default admin.py to the application template.
Thanks Ryan D Hiebert for the suggestion.
commit 4071dc771e5c44b1c5ebb9beecefb164ae465e22
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:59:49 2013 +0100
Enabled the admin by default.
Everyone uses the admin.
commit c807a31f8d89e7e7fd97380e3023f7983a8b6fcb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:57:05 2013 +0100
Removed admindocs from default project template.
commit 09e4ce0e652a97da1a9e285046a91c8ad7a9189c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:32:52 2013 +0100
Added links to the settings documentation.
commit 5b8f5eaef364eb790fcde6f9e86f7d266074cca8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 11:06:54 2013 +0100
Used a significant example for URLconf includes.
commit 908e91d6fcee2a3cb51ca26ecdf12a6a24e69ef8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:22:31 2013 +0100
Moved code comments about WSGI to docs, and rewrote said docs.
commit 50417e51996146f891d08ca8b74dcc736a581932
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 15:51:50 2013 +0100
Normalized the default application template.
Removed the default test that 1 + 1 = 2, because it's been committed
way too many times, in too many projects.
Added an import of `render` for views, because the first view will
often be:
def home(request):
return render(request, "mysite/home.html")
2013-01-28 14:51:50 +00:00
|
|
|
|
2014-12-17 21:51:42 +00:00
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
|
|
|
'django.template.context_processors.debug',
|
2015-01-12 15:48:49 +00:00
|
|
|
'django.template.context_processors.request',
|
2014-12-17 21:51:42 +00:00
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
:setting:`DIRS <TEMPLATES-DIRS>` is a list of filesystem directories to check
|
|
|
|
when loading Django templates; it's a search path.
|
Simplified default project template.
Squashed commit of:
commit 508ec9144b35c50794708225b496bde1eb5e60aa
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 22:50:55 2013 +0100
Tweaked default settings file.
* Explained why BASE_DIR exists.
* Added a link to the database configuration options, and put it in its
own section.
* Moved sensitive settings that must be changed for production at the
top.
commit 6515fd2f1aa73a86dc8dbd2ccf512ddb6b140d57
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 14:35:21 2013 +0100
Documented the simplified app & project templates in the changelog.
commit 2c5b576c2ea91d84273a019b3d0b3b8b4da72f23
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:59:27 2013 +0100
Minor fixes in tutorials 5 and 6.
commit 55a51531be8104f21b3cca3f6bf70b0a7139a041
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:51:11 2013 +0100
Updated tutorial 2 for the new project template.
commit 29ddae87bdaecff12dd31b16b000c01efbde9e20
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:58:54 2013 +0100
Updated tutorial 1 for the new project template.
commit 0ecb9f6e2514cfd26a678a280d471433375101a3
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:29:13 2013 +0100
Adjusted the default URLconf detection to account for the admin.
It's now enabled by default.
commit 5fb4da0d3d09dac28dd94e3fde92b9d4335c0565
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 10:36:55 2013 +0100
Added security warnings for the most sensitive settings.
commit 718d84bd8ac4a42fb4b28ec93965de32680f091e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:24:06 2013 +0100
Used an absolute path for the SQLite database.
This ensures the settings file works regardless of which directory
django-admin.py / manage.py is invoked from.
BASE_DIR got a +1 from a BDFL and another core dev. It doesn't involve
the concept of a "Django project"; it's just a convenient way to express
relative paths within the source code repository for non-Python files.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 1b559b4bcda622e10909b68fe5cab90db6727dd9
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:22:40 2013 +0100
Removed STATIC_ROOT from the default settings template.
It isn't necessary in development, and it confuses beginners to no end.
Thanks Carl Meyer for the suggestion.
commit a55f141a500bb7c9a1bc259bbe1954c13b199671
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:21:43 2013 +0100
Removed MEDIA_ROOT/URL from default settings template.
Many sites will never deal with user-uploaded files, and MEDIA_ROOT is
complicated to explain.
Thanks Carl Meyer for the suggestion.
commit 44bf2f2441420fd9429ee9fe1f7207f92dd87e70
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:22:09 2013 +0100
Removed logging config.
This configuration is applied regardless of the value of LOGGING;
duplicating it in LOGGING is confusing.
commit eac747e848eaed65fd5f6f254f0a7559d856f88f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:05:31 2013 +0100
Enabled the locale middleware by default.
USE_I18N is True by default, and doesn't work well without
LocaleMiddleware.
commit d806c62b2d00826dc2688c84b092627b8d571cab
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:03:16 2013 +0100
Enabled clickjacking protection by default.
commit 99152c30e6a15003f0b6737dc78e87adf462aacb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:01:48 2013 +0100
Reorganized settings in logical sections, and trimmed comments.
commit d37ffdfcb24b7e0ec7cc113d07190f65fb12fb8a
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:54:11 2013 +0100
Avoided misleading TEMPLATE_DEBUG = DEBUG.
According to the docs TEMPLATE_DEBUG works only when DEBUG = True.
commit 15d9478d3a9850e85841e7cf09cf83050371c6bf
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:46:25 2013 +0100
Removed STATICFILES_FINDERS/TEMPLATE_LOADERS from default settings file.
Only developers with special needs ever need to change these settings.
commit 574da0eb5bfb4570883756914b4dbd7e20e1f61e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:45:01 2013 +0100
Removed STATICFILES/TEMPLATES_DIRS from default settings file.
The current best practice is to put static files and templates in
applications, for easier testing and deployment.
commit 8cb18dbe56629aa1be74718a07e7cc66b4f9c9f0
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:24:16 2013 +0100
Removed settings related to email reporting from default settings file.
While handy for small scale projects, it isn't exactly a best practice.
commit 8ecbfcb3638058f0c49922540f874a7d802d864f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 18:54:43 2013 +0100
Documented how to enable the sites framework.
commit 23fc91a6fa67d91ddd9d71b1c3e0dc26bdad9841
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:28:59 2013 +0100
Disabled the sites framework by default.
RequestSite does the job for single-domain websites.
commit c4d82eb8afc0eb8568bf9c4d12644272415e3960
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 00:08:33 2013 +0100
Added a default admin.py to the application template.
Thanks Ryan D Hiebert for the suggestion.
commit 4071dc771e5c44b1c5ebb9beecefb164ae465e22
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:59:49 2013 +0100
Enabled the admin by default.
Everyone uses the admin.
commit c807a31f8d89e7e7fd97380e3023f7983a8b6fcb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:57:05 2013 +0100
Removed admindocs from default project template.
commit 09e4ce0e652a97da1a9e285046a91c8ad7a9189c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:32:52 2013 +0100
Added links to the settings documentation.
commit 5b8f5eaef364eb790fcde6f9e86f7d266074cca8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 11:06:54 2013 +0100
Used a significant example for URLconf includes.
commit 908e91d6fcee2a3cb51ca26ecdf12a6a24e69ef8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:22:31 2013 +0100
Moved code comments about WSGI to docs, and rewrote said docs.
commit 50417e51996146f891d08ca8b74dcc736a581932
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 15:51:50 2013 +0100
Normalized the default application template.
Removed the default test that 1 + 1 = 2, because it's been committed
way too many times, in too many projects.
Added an import of `render` for views, because the first view will
often be:
def home(request):
return render(request, "mysite/home.html")
2013-01-28 14:51:50 +00:00
|
|
|
|
2013-02-23 14:19:32 +00:00
|
|
|
Now create a directory called ``admin`` inside ``templates``, and copy the
|
Simplified default project template.
Squashed commit of:
commit 508ec9144b35c50794708225b496bde1eb5e60aa
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 22:50:55 2013 +0100
Tweaked default settings file.
* Explained why BASE_DIR exists.
* Added a link to the database configuration options, and put it in its
own section.
* Moved sensitive settings that must be changed for production at the
top.
commit 6515fd2f1aa73a86dc8dbd2ccf512ddb6b140d57
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 14:35:21 2013 +0100
Documented the simplified app & project templates in the changelog.
commit 2c5b576c2ea91d84273a019b3d0b3b8b4da72f23
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:59:27 2013 +0100
Minor fixes in tutorials 5 and 6.
commit 55a51531be8104f21b3cca3f6bf70b0a7139a041
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 13:51:11 2013 +0100
Updated tutorial 2 for the new project template.
commit 29ddae87bdaecff12dd31b16b000c01efbde9e20
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:58:54 2013 +0100
Updated tutorial 1 for the new project template.
commit 0ecb9f6e2514cfd26a678a280d471433375101a3
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 11:29:13 2013 +0100
Adjusted the default URLconf detection to account for the admin.
It's now enabled by default.
commit 5fb4da0d3d09dac28dd94e3fde92b9d4335c0565
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 10:36:55 2013 +0100
Added security warnings for the most sensitive settings.
commit 718d84bd8ac4a42fb4b28ec93965de32680f091e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:24:06 2013 +0100
Used an absolute path for the SQLite database.
This ensures the settings file works regardless of which directory
django-admin.py / manage.py is invoked from.
BASE_DIR got a +1 from a BDFL and another core dev. It doesn't involve
the concept of a "Django project"; it's just a convenient way to express
relative paths within the source code repository for non-Python files.
Thanks Jacob Kaplan-Moss for the suggestion.
commit 1b559b4bcda622e10909b68fe5cab90db6727dd9
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:22:40 2013 +0100
Removed STATIC_ROOT from the default settings template.
It isn't necessary in development, and it confuses beginners to no end.
Thanks Carl Meyer for the suggestion.
commit a55f141a500bb7c9a1bc259bbe1954c13b199671
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 23:21:43 2013 +0100
Removed MEDIA_ROOT/URL from default settings template.
Many sites will never deal with user-uploaded files, and MEDIA_ROOT is
complicated to explain.
Thanks Carl Meyer for the suggestion.
commit 44bf2f2441420fd9429ee9fe1f7207f92dd87e70
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:22:09 2013 +0100
Removed logging config.
This configuration is applied regardless of the value of LOGGING;
duplicating it in LOGGING is confusing.
commit eac747e848eaed65fd5f6f254f0a7559d856f88f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:05:31 2013 +0100
Enabled the locale middleware by default.
USE_I18N is True by default, and doesn't work well without
LocaleMiddleware.
commit d806c62b2d00826dc2688c84b092627b8d571cab
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:03:16 2013 +0100
Enabled clickjacking protection by default.
commit 99152c30e6a15003f0b6737dc78e87adf462aacb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 22:01:48 2013 +0100
Reorganized settings in logical sections, and trimmed comments.
commit d37ffdfcb24b7e0ec7cc113d07190f65fb12fb8a
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:54:11 2013 +0100
Avoided misleading TEMPLATE_DEBUG = DEBUG.
According to the docs TEMPLATE_DEBUG works only when DEBUG = True.
commit 15d9478d3a9850e85841e7cf09cf83050371c6bf
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:46:25 2013 +0100
Removed STATICFILES_FINDERS/TEMPLATE_LOADERS from default settings file.
Only developers with special needs ever need to change these settings.
commit 574da0eb5bfb4570883756914b4dbd7e20e1f61e
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:45:01 2013 +0100
Removed STATICFILES/TEMPLATES_DIRS from default settings file.
The current best practice is to put static files and templates in
applications, for easier testing and deployment.
commit 8cb18dbe56629aa1be74718a07e7cc66b4f9c9f0
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:24:16 2013 +0100
Removed settings related to email reporting from default settings file.
While handy for small scale projects, it isn't exactly a best practice.
commit 8ecbfcb3638058f0c49922540f874a7d802d864f
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 18:54:43 2013 +0100
Documented how to enable the sites framework.
commit 23fc91a6fa67d91ddd9d71b1c3e0dc26bdad9841
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:28:59 2013 +0100
Disabled the sites framework by default.
RequestSite does the job for single-domain websites.
commit c4d82eb8afc0eb8568bf9c4d12644272415e3960
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Tue Jan 29 00:08:33 2013 +0100
Added a default admin.py to the application template.
Thanks Ryan D Hiebert for the suggestion.
commit 4071dc771e5c44b1c5ebb9beecefb164ae465e22
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:59:49 2013 +0100
Enabled the admin by default.
Everyone uses the admin.
commit c807a31f8d89e7e7fd97380e3023f7983a8b6fcb
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 10:57:05 2013 +0100
Removed admindocs from default project template.
commit 09e4ce0e652a97da1a9e285046a91c8ad7a9189c
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:32:52 2013 +0100
Added links to the settings documentation.
commit 5b8f5eaef364eb790fcde6f9e86f7d266074cca8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 11:06:54 2013 +0100
Used a significant example for URLconf includes.
commit 908e91d6fcee2a3cb51ca26ecdf12a6a24e69ef8
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 16:22:31 2013 +0100
Moved code comments about WSGI to docs, and rewrote said docs.
commit 50417e51996146f891d08ca8b74dcc736a581932
Author: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Mon Jan 28 15:51:50 2013 +0100
Normalized the default application template.
Removed the default test that 1 + 1 = 2, because it's been committed
way too many times, in too many projects.
Added an import of `render` for views, because the first view will
often be:
def home(request):
return render(request, "mysite/home.html")
2013-01-28 14:51:50 +00:00
|
|
|
template ``admin/base_site.html`` from within the default Django admin
|
|
|
|
template directory in the source code of Django itself
|
|
|
|
(``django/contrib/admin/templates``) into that directory.
|
2005-08-07 01:00:58 +00:00
|
|
|
|
2012-07-01 10:55:46 +00:00
|
|
|
.. admonition:: Where are the Django source files?
|
|
|
|
|
|
|
|
If you have difficulty finding where the Django source files are located
|
|
|
|
on your system, run the following command:
|
|
|
|
|
2015-02-19 03:19:21 +00:00
|
|
|
.. code-block:: console
|
2012-07-01 10:55:46 +00:00
|
|
|
|
2013-12-25 19:54:14 +00:00
|
|
|
$ python -c "
|
2012-07-01 10:55:46 +00:00
|
|
|
import sys
|
|
|
|
sys.path = sys.path[1:]
|
|
|
|
import django
|
|
|
|
print(django.__path__)"
|
|
|
|
|
2014-09-22 13:40:11 +00:00
|
|
|
Then, just edit the file and replace
|
2014-10-08 12:19:11 +00:00
|
|
|
``{{ site_header|default:_('Django administration') }}`` (including the curly
|
|
|
|
braces) with your own site's name as you see fit. You should end up with
|
2014-12-26 22:48:18 +00:00
|
|
|
a section of code like:
|
2014-10-08 12:19:11 +00:00
|
|
|
|
|
|
|
.. code-block:: html+django
|
|
|
|
|
2014-12-26 22:48:18 +00:00
|
|
|
{% block branding %}
|
2014-10-08 12:19:11 +00:00
|
|
|
<h1 id="site-name"><a href="{% url 'admin:index' %}">Polls Administration</a></h1>
|
2014-12-26 22:48:18 +00:00
|
|
|
{% endblock %}
|
2014-10-08 12:19:11 +00:00
|
|
|
|
|
|
|
We use this approach to teach you how to override templates. In an actual
|
|
|
|
project, you would probably use
|
|
|
|
the :attr:`django.contrib.admin.AdminSite.site_header` attribute to more easily
|
|
|
|
make this particular customization.
|
2005-07-17 06:11:33 +00:00
|
|
|
|
2010-03-08 03:19:57 +00:00
|
|
|
This template file contains lots of text like ``{% block branding %}``
|
2010-08-18 02:42:01 +00:00
|
|
|
and ``{{ title }}``. The ``{%`` and ``{{`` tags are part of Django's
|
2010-03-08 03:19:57 +00:00
|
|
|
template language. When Django renders ``admin/base_site.html``, this
|
|
|
|
template language will be evaluated to produce the final HTML page.
|
|
|
|
Don't worry if you can't make any sense of the template right now --
|
|
|
|
we'll delve into Django's templating language in Tutorial 3.
|
|
|
|
|
2005-07-17 06:11:33 +00:00
|
|
|
Note that any of Django's default admin templates can be overridden. To
|
|
|
|
override a template, just do the same thing you did with ``base_site.html`` --
|
|
|
|
copy it from the default directory into your custom directory, and make
|
|
|
|
changes.
|
|
|
|
|
2013-02-07 10:51:25 +00:00
|
|
|
Customizing your *application's* templates
|
|
|
|
------------------------------------------
|
|
|
|
|
2014-12-17 21:51:42 +00:00
|
|
|
Astute readers will ask: But if :setting:`DIRS <TEMPLATES-DIRS>` was empty by
|
|
|
|
default, how was Django finding the default admin templates? The answer is
|
|
|
|
that, since :setting:`APP_DIRS <TEMPLATES-APP_DIRS>` is set to ``True``,
|
|
|
|
Django automatically looks for a ``templates/`` subdirectory within each
|
|
|
|
application package, for use as a fallback (don't forget that
|
2013-02-07 10:51:25 +00:00
|
|
|
``django.contrib.admin`` is an application).
|
|
|
|
|
|
|
|
Our poll application is not very complex and doesn't need custom admin
|
|
|
|
templates. But if it grew more sophisticated and required modification of
|
|
|
|
Django's standard admin templates for some of its functionality, it would be
|
|
|
|
more sensible to modify the *application's* templates, rather than those in the
|
|
|
|
*project*. That way, you could include the polls application in any new project
|
|
|
|
and be assured that it would find the custom templates it needed.
|
|
|
|
|
2015-01-03 22:05:34 +00:00
|
|
|
See the :ref:`template loading documentation <template-loading>` for more
|
2013-02-07 10:51:25 +00:00
|
|
|
information about how Django finds its templates.
|
2005-10-19 01:09:05 +00:00
|
|
|
|
2005-07-17 06:11:33 +00:00
|
|
|
Customize the admin index page
|
|
|
|
==============================
|
|
|
|
|
|
|
|
On a similar note, you might want to customize the look and feel of the Django
|
|
|
|
admin index page.
|
|
|
|
|
2008-08-23 22:25:40 +00:00
|
|
|
By default, it displays all the apps in :setting:`INSTALLED_APPS` that have been
|
|
|
|
registered with the admin application, in alphabetical order. You may want to
|
|
|
|
make significant changes to the layout. After all, the index is probably the
|
|
|
|
most important page of the admin, and it should be easy to use.
|
2005-07-17 06:11:33 +00:00
|
|
|
|
2005-10-19 01:09:05 +00:00
|
|
|
The template to customize is ``admin/index.html``. (Do the same as with
|
|
|
|
``admin/base_site.html`` in the previous section -- copy it from the default
|
|
|
|
directory to your custom template directory.) Edit the file, and you'll see it
|
2008-08-16 22:25:20 +00:00
|
|
|
uses a template variable called ``app_list``. That variable contains every
|
|
|
|
installed Django app. Instead of using that, you can hard-code links to
|
2010-03-08 03:19:57 +00:00
|
|
|
object-specific admin pages in whatever way you think is best. Again,
|
|
|
|
don't worry if you can't understand the template language -- we'll cover that
|
|
|
|
in more detail in Tutorial 3.
|
2005-07-17 06:11:33 +00:00
|
|
|
|
2010-08-19 19:27:44 +00:00
|
|
|
When you're comfortable with the admin site, read :doc:`part 3 of this tutorial
|
|
|
|
</intro/tutorial03>` to start working on public poll views.
|