views:

327

answers:

1

I'm following the Django tutorial and got stuck with an error at part 4 of the tutorial. I got to the part where I'm writing the vote view, which uses reverse to redirect to another view. For some reason, reverse fails with the following exception:

import() argument 1 must be string, not instancemethod

Currently my project's urls.py looks like this:

from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^polls/', include('mysite.polls.urls')),
(r'^admin/(.*)', include(admin.site.root)),
)

and the app urls.py is:

from django.conf.urls.defaults import *

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

And the vote view is: (I've simplified it to have only the row with the error)

def vote(request, poll_id):
    return HttpResponseRedirect(reverse('mysite.polls.views.results', args=(1,)))

When I remove the admin urls include from the project's urls.py, i.e. making it into:

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

it works.

I've tried so many things and can't understand what I'm doing wrong.

+6  A: 

The way you include the admin URLs has changed a few times over the last couple of versions. It's likely that you are using the wrong instructions for the version of Django you have installed.

If you are using the current trunk - ie not an official release - then the documentation at http://docs.djangoproject.com/en/dev/ is correct.

However, if you are using 1.0.2 then you should follow the link at the top of the page to http://docs.djangoproject.com/en/1.0/.

Daniel Roseman
Genius! :) All I had to do is change the include of the admin urls in urlspattern to: (r'^admin/(.*)', admin.site.root),instead of: (r'^admin/(.*)', include(admin.site.root)),Thanks!
arikfr