diff options
Diffstat (limited to 'docs/topics/http')
-rw-r--r-- | docs/topics/http/file-uploads.txt | 6 | ||||
-rw-r--r-- | docs/topics/http/generic-views.txt | 4 | ||||
-rw-r--r-- | docs/topics/http/index.txt | 2 | ||||
-rw-r--r-- | docs/topics/http/middleware.txt | 14 | ||||
-rw-r--r-- | docs/topics/http/sessions.txt | 10 | ||||
-rw-r--r-- | docs/topics/http/shortcuts.txt | 2 | ||||
-rw-r--r-- | docs/topics/http/urls.txt | 105 | ||||
-rw-r--r-- | docs/topics/http/views.txt | 4 |
8 files changed, 107 insertions, 40 deletions
diff --git a/docs/topics/http/file-uploads.txt b/docs/topics/http/file-uploads.txt index ab8277599c..6b0a4d5722 100644 --- a/docs/topics/http/file-uploads.txt +++ b/docs/topics/http/file-uploads.txt @@ -1,5 +1,3 @@ -.. _topics-http-file-uploads: - ============ File Uploads ============ @@ -10,8 +8,8 @@ File Uploads When Django handles a file upload, the file data ends up placed in :attr:`request.FILES <django.http.HttpRequest.FILES>` (for more on the -``request`` object see the documentation for :ref:`request and response objects -<ref-request-response>`). This document explains how files are stored on disk +``request`` object see the documentation for :doc:`request and response objects +</ref/request-response>`). This document explains how files are stored on disk and in memory, and how to customize the default behavior. Basic file uploads diff --git a/docs/topics/http/generic-views.txt b/docs/topics/http/generic-views.txt index 5aa2c48ea5..15f895ea78 100644 --- a/docs/topics/http/generic-views.txt +++ b/docs/topics/http/generic-views.txt @@ -1,7 +1,5 @@ -.. _topics-http-generic-views: - ============= Generic views ============= -See :ref:`ref-generic-views`.
\ No newline at end of file +See :doc:`/ref/generic-views`. diff --git a/docs/topics/http/index.txt b/docs/topics/http/index.txt index ae73c2c29b..5ef776dd7b 100644 --- a/docs/topics/http/index.txt +++ b/docs/topics/http/index.txt @@ -1,5 +1,3 @@ -.. _topics-http-index: - Handling HTTP requests ====================== diff --git a/docs/topics/http/middleware.txt b/docs/topics/http/middleware.txt index 215a4ec12c..eee398a3dc 100644 --- a/docs/topics/http/middleware.txt +++ b/docs/topics/http/middleware.txt @@ -1,5 +1,3 @@ -.. _topics-http-middleware: - ========== Middleware ========== @@ -14,8 +12,8 @@ an ``"X-View"`` HTTP header to every response to a ``HEAD`` request. This document explains how middleware works, how you activate middleware, and how to write your own middleware. Django ships with some built-in middleware -you can use right out of the box; they're documented in the :ref:`built-in -middleware reference <ref-middleware>`. +you can use right out of the box; they're documented in the :doc:`built-in +middleware reference </ref/middleware>`. Activating middleware ===================== @@ -173,9 +171,9 @@ Guidelines cares about is that the :setting:`MIDDLEWARE_CLASSES` setting includes the path to it. - * Feel free to look at :ref:`Django's available middleware - <ref-middleware>` for examples. + * Feel free to look at :doc:`Django's available middleware + </ref/middleware>` for examples. * If you write a middleware component that you think would be useful to - other people, contribute to the community! :ref:`Let us know - <internals-contributing>`, and we'll consider adding it to Django. + other people, contribute to the community! :doc:`Let us know + </internals/contributing>`, and we'll consider adding it to Django. diff --git a/docs/topics/http/sessions.txt b/docs/topics/http/sessions.txt index 68ead03b65..8a0f0d4b72 100644 --- a/docs/topics/http/sessions.txt +++ b/docs/topics/http/sessions.txt @@ -1,5 +1,3 @@ -.. _topics-http-sessions: - =================== How to use sessions =================== @@ -15,7 +13,7 @@ Cookies contain a session ID -- not the data itself. Enabling sessions ================= -Sessions are implemented via a piece of :ref:`middleware <ref-middleware>`. +Sessions are implemented via a piece of :doc:`middleware </ref/middleware>`. To enable session functionality, do the following: @@ -56,8 +54,8 @@ For better performance, you may want to use a cache-based session backend. Django 1.0 did not include the ``cached_db`` session backend. To store session data using Django's cache system, you'll first need to make -sure you've configured your cache; see the :ref:`cache documentation -<topics-cache>` for details. +sure you've configured your cache; see the :doc:`cache documentation +</topics/cache>` for details. .. warning:: @@ -412,7 +410,7 @@ in the past -- but your application may have different requirements. Settings ======== -A few :ref:`Django settings <ref-settings>` give you control over session behavior: +A few :doc:`Django settings </ref/settings>` give you control over session behavior: SESSION_ENGINE -------------- diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt index 5510613355..6bd3058941 100644 --- a/docs/topics/http/shortcuts.txt +++ b/docs/topics/http/shortcuts.txt @@ -1,5 +1,3 @@ -.. _topics-http-shortcuts: - ========================= Django shortcut functions ========================= diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index 5a2980f9d2..1f499909ee 100644 --- a/docs/topics/http/urls.txt +++ b/docs/topics/http/urls.txt @@ -1,5 +1,3 @@ -.. _topics-http-urls: - ============== URL dispatcher ============== @@ -335,7 +333,7 @@ The view prefix You can specify a common prefix in your ``patterns()`` call, to cut down on code duplication. -Here's the example URLconf from the :ref:`Django overview <intro-overview>`:: +Here's the example URLconf from the :doc:`Django overview </intro/overview>`:: from django.conf.urls.defaults import * @@ -537,8 +535,8 @@ In this example, for a request to ``/blog/2005/``, Django will call the year='2005', foo='bar' -This technique is used in :ref:`generic views <ref-generic-views>` and in the -:ref:`syndication framework <ref-contrib-syndication>` to pass metadata and +This technique is used in :doc:`generic views </ref/generic-views>` and in the +:doc:`syndication framework </ref/contrib/syndication>` to pass metadata and options to views. .. admonition:: Dealing with conflicts @@ -827,17 +825,80 @@ namespaces into URLs on specific application instances, according to the resolve() --------- -The :func:`django.core.urlresolvers.resolve` function can be used for resolving -URL paths to the corresponding view functions. It has the following signature: +The :func:`django.core.urlresolvers.resolve` function can be used for +resolving URL paths to the corresponding view functions. It has the +following signature: .. function:: resolve(path, urlconf=None) -``path`` is the URL path you want to resolve. As with ``reverse()`` above, you -don't need to worry about the ``urlconf`` parameter. The function returns the -triple (view function, arguments, keyword arguments). +``path`` is the URL path you want to resolve. As with +:func:`~django.core.urlresolvers.reverse`, you don't need to +worry about the ``urlconf`` parameter. The function returns a +:class:`django.core.urlresolvers.ResolverMatch` object that allows you +to access various meta-data about the resolved URL. + +.. class:: ResolverMatch() + + .. attribute:: ResolverMatch.func + + The view function that would be used to serve the URL + + .. attribute:: ResolverMatch.args + + The arguments that would be passed to the view function, as + parsed from the URL. + + .. attribute:: ResolverMatch.kwargs + + The keyword arguments that would be passed to the view + function, as parsed from the URL. + + .. attribute:: ResolverMatch.url_name + + The name of the URL pattern that matches the URL. + + .. attribute:: ResolverMatch.app_name + + The application namespace for the URL pattern that matches the + URL. + + .. attribute:: ResolverMatch.namespace + + The instance namespace for the URL pattern that matches the + URL. -For example, it can be used for testing if a view would raise a ``Http404`` -error before redirecting to it:: + .. attribute:: ResolverMatch.namespaces + + The list of individual namespace components in the full + instance namespace for the URL pattern that matches the URL. + i.e., if the namespace is ``foo:bar``, then namespaces will be + ``[`foo`, `bar`]``. + +A :class:`~django.core.urlresolvers.ResolverMatch` object can then be +interrogated to provide information about the URL pattern that matches +a URL:: + + # Resolve a URL + match = resolve('/some/path/') + # Print the URL pattern that matches the URL + print match.url_name + +A :class:`~django.core.urlresolvers.ResolverMatch` object can also be +assigned to a triple:: + + func, args, kwargs = resolve('/some/path/') + +.. versionchanged:: 1.3 + Triple-assignment exists for backwards-compatibility. Prior to + Django 1.3, :func:`~django.core.urlresolvers.resolve` returned a + triple containing (view function, arguments, keyword arguments); + the :class:`~django.core.urlresolvers.ResolverMatch` object (as + well as the namespace and pattern information it provides) is not + available in earlier Django releases. + +One possible use of :func:`~django.core.urlresolvers.resolve` would be +to testing if a view would raise a ``Http404`` error before +redirecting to it:: from urlparse import urlparse from django.core.urlresolvers import resolve @@ -858,9 +919,29 @@ error before redirecting to it:: return HttpResponseRedirect('/') return response + permalink() ----------- The :func:`django.db.models.permalink` decorator is useful for writing short methods that return a full URL path. For example, a model's ``get_absolute_url()`` method. See :func:`django.db.models.permalink` for more. + +get_script_prefix() +------------------- + +.. function:: get_script_prefix() + +.. versionadded:: 1.0 + +Normally, you should always use :func:`~django.core.urlresolvers.reverse` or +:func:`~django.db.models.permalink` to define URLs within your application. +However, if your application constructs part of the URL hierarchy itself, you +may occasionally need to generate URLs. In that case, you need to be able to +find the base URL of the Django project within its web server +(normally, :func:`~django.core.urlresolvers.reverse` takes care of this for +you). In that case, you can call ``get_script_prefix()``, which will return the +script prefix portion of the URL for your Django project. If your Django +project is at the root of its webserver, this is always ``"/"``, but it can be +changed, for instance by using ``django.root`` (see :ref:`How to use +Django with Apache and mod_python <howto-deployment-modpython>`). diff --git a/docs/topics/http/views.txt b/docs/topics/http/views.txt index 7d8743fe06..399e6b6ad1 100644 --- a/docs/topics/http/views.txt +++ b/docs/topics/http/views.txt @@ -1,5 +1,3 @@ -.. _topics-http-views: - ============= Writing Views ============= @@ -59,7 +57,7 @@ Mapping URLs to Views So, to recap, this view function returns an HTML page that includes the current date and time. To display this view at a particular URL, you'll need to create a -*URLconf*; see :ref:`topics-http-urls` for instructions. +*URLconf*; see :doc:`/topics/http/urls` for instructions. Returning errors ================ |