I am using Django 1.2.3-3+squeeze1
with Debian squeeze.
I am trying to use the Django password change view in my application
corresponding to django.contrib.auth.views.password_change
. This
looks like it should be straightforward, but I have been having
problems.
For simplicity and completeness, I will point to my application files online. The application is bixfile. The corresponding Django project is bixproj.
The relevant line in url.py is https://bitbucket.org/faheem/bixfile/src/49bcbab3a7be/urls.py#cl-65, namely
url(r'^password_change/$', 'django.contrib.auth.views.password_change', {'post_change_redirect':reverse('top_folders')}, name="password_change"),
This breaks any template in which it is used. Currently, I'm only using it at line https://bitbucket.org/faheem/bixfile/src/71de33d01f43/templates/calgb_base.html#cl-21 of the template calgb_base.html, which is included in a bunch of templates including the top level index view, corresponding to the template https://bitbucket.org/faheem/bixfile/src/71de33d01f43/templates/index.html. The line in calgb_base.html is
<li><a class="side" href="{% url password_change %}">Password Change开发者_如何学Python</a></li>
When I navigate to the top index
view corresponding to
https://bitbucket.org/faheem/bixfile/src/71de33d01f43/urls.py#cl-16
and
https://bitbucket.org/faheem/bixfile/src/71de33d01f43/views.py#cl-203
I see an error, beginning with
Caught NoReverseMatch while rendering: Reverse for 'password_change'
with arguments '()' and keyword arguments '{}' not found.
I doubt the full traceback is useful, but I have pasted it at http://paste.lisp.org/display/122996.
This error is reproducible with both Apache 2.2 and mod-wsgi, as well as the builtin Django test server (see below).
If I go directly the the /password_change/ relative url, I see the password change form as expected.
The weird thing is that all the tests I have written to test this pass, and produce the expected result. See for example testIndexUrl , testIndexView and test_password_change_url.
You can run the tests from the bixproj
directory with
python manage.py test
If you want to try to reproduce this error it is comparatively easy.
First download the project (bixproj
) and application repositories
(bixfile
). So
hg clone ssh://hg@bitbucket.org/faheem/bixproj
hg clone ssh://hg@bitbucket.org/faheem/bixfile
Then make sure bixfile is in the Python path. Change DATABASES to use sqlite. Then change
LOGIN_URL = '/'+BIXFILE_NAME+'/login/'
LOGIN_REDIRECT_URL= '/'+BIXFILE_NAME+'/'
to
LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL= '/'
Then running
python manage.py runserver
in the bixproj
directory on a local machine and going to the default url
http://127.0.0.1:8000/
should display the error.
I expect I can produce a minimal example showing the error if necessary, but I'm really hoping this error is obvious and I don't have to. Thanks in advance.
Your bixfiles.urls
uses reverse
. This is not possible, because the urls have not been loaded when reverse
is called.
Django 1.4 will have a reverse_lazy
feature that will solve this problem.
In the meantime, you can:
- Implement
reverse_lazy
in your project (see changeset 16121). - Hardcode the urls instead of using reverse
精彩评论