Django模板错误:无法解析剩余部分:','从'uid,'?

6

我正在使用带有自定义模板的Django forgot_password框架。 我使用的是Django 1.5。 我的自定义模板password_reset_email.html如下所示:

{% autoescape off %}
You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}.

Please go to the following page and choose a new password:
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}
{% endblock %}

Your username, in case you've forgotten: {{ user.username }}

Thanks for using our site!

The {{ site_name }} team.

{% endautoescape %}

#Exception:
Exception Type: TemplateSyntaxError at /accounts/password/reset/
Exception Value: Could not parse the remainder: ',' from 'uid,'
4个回答

16

请将此放置在顶部:

 {% load i18n %}{% load url from future %}
 {% autoescape off %}
 ..........

移除,,把它放在uidb36=uid旁边。

 {% url 'django.contrib.auth.views.password_reset_confirm' uidb36=uid token=token %}

在我接受答案之前,我有一个问题,我想要将密码重置URL与我的URL一起使用。我应该手动输入还是?现在,我想让它转到127.0.0.1:8000而不是example.com。 - pynovice
这里没有协议和域名 {{ protocol }}://{{ domain }}, 它们存储在数据库中吗? - pynovice
不要更改协议,它是自动的,可以是http、https或其他任何协议。 - catherine

11

因此,模板中真正的问题是视图周围缺少引号,并且在uid之后有额外的','字符? - winwaed
只是一个备注,确认Derek的答案和winwaed的评论。修复引号并删除评论对我来说是正确的答案。+1 - Guerry

1

截至2022年(django版本4.0.5),这里的任何答案都对我没有用。我不得不更改以下行:

{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}

to:

{% url 'password_reset_confirm' uid token %}

password_reset_confirm是我在urls.py文件中为密码重置确认视图命名的名称,该文件位于我管理用户注册系统的应用程序(该应用程序名为users)中:

path('pattern/<uidb64>/<token>', django.contrib.auth.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), name='password_reset_confirm')

0

我的问题已经通过编写以下内容得到解决 我正在使用Django 4.1

{% url 'password_reset_confirm' uidb64=uid token=token %}


这个回答是否解决了隐含的问题“如何摆脱Django模板错误:无法解析余额:',' from 'uid,'”?(你的问题是什么?) - greybeard

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接