Django模板错误:无法解析其余部分:','来自'uid,'?

wljmcqd8  于 2023-03-13  发布在  Go
关注(0)|答案(4)|浏览(141)

我使用的是带有自定义模板的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,'
e0uiprwp

e0uiprwp1#

把这个放在上面:

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

删除,,将其放在uidb36=uid,旁边

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

n6lpvg4x2#

我没有足够的信誉点数来评论已接受的答案,但{% load url from future %}不应该是必需的,因为您使用的是Django 1.5。它只在Django 1.3和1.4中需要。https://docs.djangoproject.com/en/dev/releases/1.3/#changes-to-url-and-ssi

2cmtqfgy

2cmtqfgy3#

截至2022年(django4.0.5版),这里的答案对我来说都不管用,我不得不改了一行:

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

致:

{% url 'password_reset_confirm' uid token %}

其中password_reset_confirm是我在url模式中为 * 密码重置确认 * 视图指定的name,它位于我管理用户注册系统的应用程序(该应用程序称为users)中的urls.py文件中:

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

1szpjjfi4#

我的问题通过写这个得到了解决我使用的是django 4. 1
{% url“密码重置确认”uidb 64 =uid标记=标记%}

相关问题