diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-11-11 04:45:05 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-11-11 04:45:05 +0000 |
| commit | 1b035c35d9bb288589d813393e635bc9546c914b (patch) | |
| tree | 636e84011113d7f542cfaf45ea0921e2470e0ba6 /docs | |
| parent | a11a1d5e1690fb334758fc2dbaa5478aecc8ab63 (diff) | |
BACKWARDS-INCOMPATIBLE CHANGE -- Moved flatpages and redirects to standalone apps in django.contrib that are NOT installed by default. See http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges for full migration information.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1166 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/flatpages.txt | 114 | ||||
| -rw-r--r-- | docs/legacy_databases.txt | 3 | ||||
| -rw-r--r-- | docs/middleware.txt | 4 | ||||
| -rw-r--r-- | docs/model-api.txt | 2 | ||||
| -rw-r--r-- | docs/redirects.txt | 72 | ||||
| -rw-r--r-- | docs/settings.txt | 8 | ||||
| -rw-r--r-- | docs/url_dispatch.txt | 1 |
7 files changed, 187 insertions, 17 deletions
diff --git a/docs/flatpages.txt b/docs/flatpages.txt new file mode 100644 index 0000000000..5c0520dae0 --- /dev/null +++ b/docs/flatpages.txt @@ -0,0 +1,114 @@ +================= +The flatpages app +================= + +Django comes with an optional "flatpages" application. It lets you store simple +"flat" HTML content in a database and handles the management for you. + +A flatpage is a simple object with a URL, title and content. Use it for +one-off, special-case pages, such as "About" or "Privacy Policy" pages, that +you want to store in a database but for which you don't want to develop a +custom Django application. + +A flatpage can use a custom template or a default, systemwide flatpage +template. It can be associated with one, or multiple, sites. + +Here are some examples of flatpages on Django-powered sites: + + * http://www.chicagocrime.org/about/ + * http://www.lawrence.com/about/contact/ + +Installation +============ + +To install the flatpages app, follow these two steps: + + 1. Add ``"django.contrib.flatpages"`` to your INSTALLED_APPS_ setting. + 2. Add ``"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware"`` + to your MIDDLEWARE_CLASSES_ setting. + 3. Run the command ``django-admin.py install flatpages``. + +.. _INSTALLED_APPS: http://www.djangoproject.com/documentation/settings/#installed-apps +.. _MIDDLEWARE_CLASSES: http://www.djangoproject.com/documentation/settings/#middleware-classes + +How it works +============ + +``django-admin.py install flatpages`` creates two tables in your database: +``django_flatpages`` and ``django_flatpages_sites``. ``django_flatpages`` is a +simple lookup table that essentially maps a URL to a title and bunch of text +content. ``django_flatpages_sites`` associates a flatpage with a site. + +The ``FlatpageFallbackMiddleware`` does all of the work. Each time any Django +application raises a 404 error, this middleware checks the flatpages database +for the requested URL as a last resort. Specifically, it checks for a flatpage +with the given URL with a site ID that corresponds to the SITE_ID_ setting. + +If it finds a match, it follows this algorithm: + + * If the flatpage has a custom template, it loads that template. Otherwise, + it loads the template ``flatpages/default``. + * It passes that template a single context variable, ``flatpage``, which is + the flatpage object. It uses DjangoContext_ in rendering the template. + +If it doesn't find a match, the request continues to be processed as usual. + +The middleware only gets activated for 404s -- not for 500s or responses of any +other status code. + +Note that the order of ``MIDDLEWARE_CLASSES`` matters. Generally, you can put +``FlatpageFallbackMiddleware`` at the end of the list, because it's a last +resort. + +For more on middleware, read the `middleware docs`_. + +.. _SITE_ID: http://www.djangoproject.com/documentation/settings/#site-id +.. _DjangoContext: http://www.djangoproject.com/documentation/templates_python/#subclassing-context-djangocontext +.. _middleware docs: http://www.djangoproject.com/documentation/middleware/ + +How to add, change and delete flatpages +======================================= + +Via the admin interface +----------------------- + +If you've activated the automatic Django admin interface, you should see a +"Flatpages" section on the admin index page. Edit flatpages as you edit any +other object in the system. + +Via the Python API +------------------ + +Flatpages are represented by a standard `Django model`_, which lives in +`django/contrib/flatpages/models/flatpages.py`_. You can access flatpage +objects via the `Django database API`_. + +.. _Django model: http://www.djangoproject.com/documentation/model_api/ +.. _django/contrib/flatpages/models/flatpages.py: http://code.djangoproject.com/browser/django/trunk/django/contrib/flatpages/models/flatpages.py +.. _Django database API: http://www.djangoproject.com/documentation/db_api/ + +Flatpage templates +================== + +By default, flatpages are rendered via the template ``flatpages/default``, but +you can override that for a particular flatpage. + +Creating the ``flatpages/default`` template is your responsibility; in your +template directory, just create a ``flatpages`` directory containing a file +``default.html``. + +Flatpage templates are passed a single context variable, ``flatpage``, which is +the flatpage object. + +Here's a sample ``flatpages/default`` template:: + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" + "http://www.w3.org/TR/REC-html40/loose.dtd"> + <html> + <head> + <title>{{ flatpage.title }}</title> + </head> + <body> + {{ flatpage.content }} + </body> + </html> diff --git a/docs/legacy_databases.txt b/docs/legacy_databases.txt index beddc74134..f1b8f85970 100644 --- a/docs/legacy_databases.txt +++ b/docs/legacy_databases.txt @@ -69,10 +69,7 @@ following names: * ``sites`` * ``packages`` * ``content_types`` - * ``redirects`` - * ``flatfiles`` * ``core_sessions`` - * ``flatfiles_sites`` * ``auth_permissions`` * ``auth_groups`` * ``auth_users`` diff --git a/docs/middleware.txt b/docs/middleware.txt index a7a5474d84..5a01f728d4 100644 --- a/docs/middleware.txt +++ b/docs/middleware.txt @@ -72,10 +72,6 @@ Adds a few conveniences for perfectionists: MD5-hashing the page content, and it'll take care of sending ``Not Modified`` responses, if appropriate. -* Handles flat pages. Every time Django encounters a 404 -- either within - a view or as a result of no URLconfs matching -- it will check the - database of flat pages based on the current URL. - django.middleware.doc.XViewMiddleware ------------------------------------- diff --git a/docs/model-api.txt b/docs/model-api.txt index a9190c78fe..51086e426e 100644 --- a/docs/model-api.txt +++ b/docs/model-api.txt @@ -831,7 +831,7 @@ object, which takes the following parameters. All are optional. "click to expand" link. Fieldsets with the ``wide`` style will be given extra horizontal space. - For example (taken from the ``core.flatfiles`` model):: + For example (taken from the ``django.contrib.flatpages`` model):: fields = ( (None, { diff --git a/docs/redirects.txt b/docs/redirects.txt new file mode 100644 index 0000000000..08fae8a8dc --- /dev/null +++ b/docs/redirects.txt @@ -0,0 +1,72 @@ +================= +The redirects app +================= + +Django comes with an optional redirects application. It lets you store simple +redirects in a database and handles the redirecting for you. + +Installation +============ + +To install the redirects app, follow these two steps: + + 1. Add ``"django.contrib.redirects"`` to your INSTALLED_APPS_ setting. + 2. Add ``"django.contrib.redirects.middleware.RedirectFallbackMiddleware"`` + to your MIDDLEWARE_CLASSES_ setting. + 3. Run the command ``django-admin.py install redirects``. + +.. _INSTALLED_APPS: http://www.djangoproject.com/documentation/settings/#installed-apps +.. _MIDDLEWARE_CLASSES: http://www.djangoproject.com/documentation/settings/#middleware-classes + +How it works +============ + +``django-admin.py install redirects`` creates a ``django_redirects`` table in +your database. This is a simple lookup table with ``site_id``, ``old_path`` and +``new_path`` fields. + +The ``RedirectFallbackMiddleware`` does all of the work. Each time any Django +application raises a 404 error, this middleware checks the redirects database +for the requested URL as a last resort. Specifically, it checks for a redirect +with the given ``old_path`` with a site ID that corresponds to the SITE_ID_ +setting. + + * If it finds a match, and ``new_path`` is not empty, it redirects to + ``new_path``. + * If it finds a match, and ``new_path`` is empty, it sends a 410 ("Gone") + HTTP header and empty (content-less) response. + * If it doesn't find a match, the request continues to be processed as + usual. + +The middleware only gets activated for 404s -- not for 500s or responses of any +other status code. + +Note that the order of ``MIDDLEWARE_CLASSES`` matters. Generally, you can put +``RedirectFallbackMiddleware`` at the end of the list, because it's a last +resort. + +For more on middleware, read the `middleware docs`_. + +.. _SITE_ID: http://www.djangoproject.com/documentation/settings/#site-id +.. _middleware docs: http://www.djangoproject.com/documentation/middleware/ + +How to add, change and delete redirects +======================================= + +Via the admin interface +----------------------- + +If you've activated the automatic Django admin interface, you should see a +"Redirects" section on the admin index page. Edit redirects as you edit any +other object in the system. + +Via the Python API +------------------ + +Redirects are represented by a standard `Django model`_, which lives in +`django/contrib/redirects/models/redirects.py`_. You can access redirect +objects via the `Django database API`_. + +.. _Django model: http://www.djangoproject.com/documentation/model_api/ +.. _django/contrib/redirects/models/redirects.py: http://code.djangoproject.com/browser/django/trunk/django/contrib/redirects/models/redirects.py +.. _Django database API: http://www.djangoproject.com/documentation/db_api/ diff --git a/docs/settings.txt b/docs/settings.txt index c4eeb2e636..b5287b26a2 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -562,14 +562,6 @@ A boolean that specifies whether to output the "Etag" header. This saves bandwidth but slows down performance. This is only used if ``CommonMiddleware`` is installed (see the `middleware docs`_). -USE_FLAT_PAGES --------------- - -Default: ``True`` - -Whether to check the flat-pages table as a last resort for all 404 errors. This -is only used if ``CommonMiddleware`` is installed (see the `middleware docs`_). - .. _cache docs: http://www.djangoproject.com/documentation/cache/ .. _middleware docs: http://www.djangoproject.com/documentation/middleware/ .. _session docs: http://www.djangoproject.com/documentation/sessions/ diff --git a/docs/url_dispatch.txt b/docs/url_dispatch.txt index 3a3feea8be..363d31174a 100644 --- a/docs/url_dispatch.txt +++ b/docs/url_dispatch.txt @@ -56,7 +56,6 @@ module that will be used for the entire site. Here's the URLconf for the (r'^documentation/', include('django_website.apps.docs.urls.docs')), (r'^comments/', include('django.contrib.comments.urls.comments')), (r'^rss/', include('django.conf.urls.rss')), - (r'', include('django.conf.urls.flatfiles')), ) Note that an included URLconf receives any captured parameters from parent |
