Reputation: 159
Situation in short. For some reason reverse() method does not work.
in PROJECT urls.py
url(r'^enrollment/', include('project.enrollment.urls')),
in APP urls.py
url(r'^thanks/$', 'enrollment.views.thanks', name='enroll_thanks'),
and in views.py
from django.core.urlresolvers import reverse
def thanks(request):
return render_to_response('enrollment/thanks.html', {}, context_instance=RequestContext(request))
def enroll(request):
''' some code for handling the form'''
return HttpResponseRedirect(reverse('enrollment.views.thanks'))
This reverse causes following error: Could not import project.views. Error was: No module named views
in file ../django/core/urlresolvers.py in _get_callback, line 167
Any idea why this does not work? Next step is to call the thanks-view with a parameter, but that should be easy after this setup works. Should there be something more to be imported in views.py?
Upvotes: 4
Views: 21117
Reputation: 4047
From the docs for reverse: "As part of working out which URL names map to which patterns, the reverse() function has to import all of your URLconf files and examine the name of each view. This involves importing each view function. If there are any errors whilst importing any of your view functions, it will cause reverse() to raise an error, even if that view function is not the one you are trying to reverse."
Are any of your urls referencing project.views.
...?
Upvotes: 5
Reputation: 13722
Not too sure of your module layout but based on your include() line in urls.py it looks like you may want to add "project." to the argument in your reverse() call as well.
reverse('project.enrollment.views.thanks')
That or you may have a bug in the view.
Upvotes: -1