带有password_change视图的模板中的Django url错误

发布于 2024-11-17 14:39:07 字数 3582 浏览 4 评论 0原文

我正在使用 Django 1.2.3-3+squeeze1 和 Debian squeeze。

我正在尝试在我的应用程序中使用 Django 密码更改视图 对应于django.contrib.auth.views.password_change。这 看起来应该很简单,但我一直有 问题。

为了简单和完整起见,我将指向我的应用程序文件 在线的。该应用程序是bixfile。这 对应的 Django 项目是 bixproj

url.py 中的相关行是 https://bitbucket.org/faheem/bixfile/src/49bcbab3a7be /urls.py#cl-65, 即

url(r'^password_change/$', 'django.contrib.auth.views.password_change', {'post_change_redirect':reverse('top_folders')}, name="password_change"),

这会破坏使用它的任何模板。目前,我只是 在线使用它 https://bitbucket.org/faheem/bixfile/src /71de33d01f43/templates/calgb_base.html#cl-21 模板 calgb_base.html 包含在一堆 模板包括顶级索引视图,对应于 模板 https://bitbucket.org/faheem/bixfile/src/71de33d01f43/templates /index.html。这 calgb_base.html 中的行是

<li><a class="side" href="{% url password_change %}">Password Change</a></li>

当我导航到对应于的顶部 index 视图时 https://bitbucket.org/faheem/bixfile/src/71de33d01f43 /urls.py#cl-16https://bitbucket.org/faheem/bixfile/src/71de33d01f43 /views.py#cl-203 我看到一个错误,首先

Caught NoReverseMatch while rendering: Reverse for 'password_change'
with arguments '()' and keyword arguments '{}' not found.

我怀疑完整的回溯是否有用,但我已将其粘贴在 http://paste.lisp.org/display/122996

Apache 2.2 和 mod-wsgi 也可以重现此错误 作为内置 Django 测试服务器(见下文)。

如果我直接进入 /password_change/ 相对网址,我会看到 密码更改形式如预期。

奇怪的是我写的所有测试都是为了测试这个 通过,并产生预期的结果。参见示例 testIndexUrl , testIndexViewtest_password_change_url

您可以从 bixproj 目录运行测试,

python manage.py test

如果您想尝试重现此错误,这相对容易。

首先下载项目 (bixproj) 和应用程序存储库 (bixfile)。然后

hg clone ssh://[email protected]/faheem/bixproj
hg clone ssh://[email protected]/faheem/bixfile

确保 bixfile 在 Python 路径中。更改要使用的数据库 sqlite。然后更改

LOGIN_URL = '/'+BIXFILE_NAME+'/login/'
LOGIN_REDIRECT_URL= '/'+BIXFILE_NAME+'/'

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL= '/'

“然后

python manage.py runserver

在本地计算机上的 bixproj 目录中运行”并转到默认 url http://127.0.0.1:8000/ 应该显示错误。

我希望我可以生成一个最小的示例来显示错误,如果 必要的,但我真的希望这个错误是明显的,但我不希望 必须。提前致谢。

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/

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</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://[email protected]/faheem/bixproj
hg clone ssh://[email protected]/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.

, '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

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

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

If you want to try to reproduce this error it is comparatively easy.

First download the project (bixproj) and application repositories
(bixfile). So

Then make sure bixfile is in the Python path. Change DATABASES to use
sqlite. Then change

to

Then running

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似梦非梦 2024-11-24 14:39:07

您的 bixfiles.urls 使用 reverse。这是不可能的,因为调用 reverse 时尚未加载 url。

Django 1.4 将有一个 reverse_lazy< /a> 功能可以解决这个问题。

同时,您可以:

  1. 在您的项目中实现 reverse_lazy (请参阅 变更集 16121)。
  2. 对 url 进行硬编码而不是使用反向

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:

  1. Implement reverse_lazy in your project (see changeset 16121).
  2. Hardcode the urls instead of using reverse
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文