views:

137

answers:

1

So now I am still at the Django tutorial part 3:

http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03

Trying to set up the urls.py with this piece of code provided by the tutorial

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^polls/$', 'mysite.polls.views.index'),
    (r'^polls/(?P<poll_id>\d+)/$', 'mysite.polls.views.detail'),
    (r'^polls/(?P<poll_id>\d+)/results/$', 'mysite.polls.views.results'),
    (r'^polls/(?P<poll_id>\d+)/vote/$', 'mysite.polls.views.vote'),
    (r'^admin/', include(admin.site.urls)),
)

If I change my default urls.py (with nothing in it) with this code, the 127.0.0.1:8000/polls/ is showing up, but for some reason the 127.0.0.1:8000/admin is no longer there and gives me the following error:

Exception Type: TemplateSyntaxError Exception Value: Caught an exception while rendering: Tried vote in module mysite.polls.views. Error was: 'module' object has no attribute 'vote'

And this (Error line 30): 

Caught an exception while rendering: Tried vote in module mysite.polls.views. Error was: 'module' object has no attribute 'vote'
20  <!-- Header -->
21  <div id="header">
22  <div id="branding">
23  {% block branding %}{% endblock %}
24  </div>
25  {% if user.is_authenticated and user.is_staff %}
26  <div id="user-tools">
27  {% trans 'Welcome,' %}
28  <strong>{% firstof user.first_name user.username %}</strong>.
29  {% block userlinks %}
**30    {% url django-admindocs-docroot as docsroot %}**
31  {% if docsroot %}
32  <a href="{{ docsroot }}">{% trans 'Documentation' %}</a> /
33  {% endif %}
34  {% url admin:password_change as password_change_url %}
35  {% if password_change_url %}
36  <a href="{{ password_change_url }}">
37  {% else %}
38  <a href="{{ root_path }}password_change/">
39  {% endif %}
40  {% trans 'Change password' %}</a> / 

It seems to me that the error should be here:

(r'^admin/', include(admin.site.urls)),

But I cant find it.

Thanks for the attention!!

+1  A: 

It's just that django does not seem to find the function vote inside your module views.

Olivier
Thanks! What does this piece of code do exactly?(r'^polls/(?P<poll_id>\d+)/vote/$', 'mysite.polls.views.vote')I understand its regular expressions but not more than that.And it is strange that the polls site will work, but the admin site not. I dont understand that part.I read that later in the tutorial they create a vote function.
MacPython
It's a regular expression that selects which view function will be called. If the url matches the regexp, then the function 'mysite...' is called.
Olivier