Commit f14833ee authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #11959 -- Updated the tutorial to ensure that the admin site continues...

Fixed #11959 -- Updated the tutorial to ensure that the admin site continues to work after URLpatterns are introduced. Thanks to carljm for the report and draft patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11621 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent b30cba4e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -281,6 +281,7 @@ That'll create a directory :file:`polls`, which is laid out like this::
    polls/
        __init__.py
        models.py
        tests.py
        views.py

This directory structure will house the poll application.
+5 −5
Original line number Diff line number Diff line
@@ -34,11 +34,11 @@ activate the admin site for your installation, do these three things:
    * Run ``python manage.py syncdb``. Since you have added a new application
      to :setting:`INSTALLED_APPS`, the database tables need to be updated.

    * Edit your ``mysite/urls.py`` file and uncomment the lines below the
      "Uncomment the next two lines..." comment. This file is a URLconf;
      we'll dig into URLconfs in the next tutorial. For now, all you need to
      know is that it maps URL roots to applications. In the end, you should
      have a ``urls.py`` file that looks like this:
    * Edit your ``mysite/urls.py`` file and uncomment the lines that reference
      the admin -- there are three lines in total to uncomment. This file is a
      URLconf; we'll dig into URLconfs in the next tutorial. For now, all you
      need to know is that it maps URL roots to applications. In the end, you
      should have a ``urls.py`` file that looks like this:

    .. versionchanged:: 1.1
        The method for adding admin urls has changed in Django 1.1.
+15 −7
Original line number Diff line number Diff line
@@ -171,15 +171,23 @@ and put the following Python code in it::
This is the simplest view possible. Go to "/polls/" in your browser, and you
should see your text.

Now add the following view. It's slightly different, because it takes an
argument (which, remember, is passed in from whatever was captured by the
regular expression in the URLconf)::
Now lets add a few more views. These views are slightly different, because
they take an argument (which, remember, is passed in from whatever was
captured by the regular expression in the URLconf)::

    def detail(request, poll_id):
        return HttpResponse("You're looking at poll %s." % poll_id)

Take a look in your browser, at "/polls/34/". It'll display whatever ID you
provide in the URL.
    def results(request, poll_id):
        return HttpResponse("You're looking at the results of poll %s." % poll_id)

    def vote(request, poll_id):
        return HttpResponse("You're voting on poll %s." % poll_id)

Take a look in your browser, at "/polls/34/". It'll run the `detail()` method
and display whatever ID you provide in the URL. Try "/polls/34/results/" and
"/polls/34/vote/" too -- these will display the placeholder results and voting
pages.

Write views that actually do something
======================================
@@ -467,10 +475,10 @@ Copy the file ``mysite/urls.py`` to ``mysite/polls/urls.py``. Then, change
``mysite/urls.py`` to remove the poll-specific URLs and insert an
:func:`~django.conf.urls.defaults.include`::

    ...
    # ...
    urlpatterns = patterns('',
        (r'^polls/', include('mysite.polls.urls')),
        ...
        # ...

:func:`~django.conf.urls.defaults.include`, simply, references another URLconf.
Note that the regular expression doesn't have a ``$`` (end-of-string match
+3 −2
Original line number Diff line number Diff line
@@ -52,10 +52,11 @@ created a URLconf for the polls application that includes this line::

    (r'^(?P<poll_id>\d+)/vote/$', 'vote'),

So let's create a ``vote()`` function in ``mysite/polls/views.py``::
We also created a dummy implementation of the ``vote()`` function. Let's
create a real version. Add the following to ``mysite/polls/views.py``::

    from django.shortcuts import get_object_or_404, render_to_response
    from django.http import HttpResponseRedirect
    from django.http import HttpResponseRedirect, HttpResponse
    from django.core.urlresolvers import reverse
    from mysite.polls.models import Choice, Poll
    # ...