【问题标题】:Django Template Error: Could not parse the remainder: ',' from 'uid,'?Django 模板错误:无法从 'uid' 解析余数:','?
【发布时间】:2013-03-17 06:36:55
【问题描述】:

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

【问题讨论】:

    标签: django forgot-password django-errors


    【解决方案1】:

    把这个放在最上面:

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

    去掉,,你把它放在uidb36=uid,旁边

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

    【讨论】:

    • 在我接受答案之前还有一个问题,我想要密码重置 URL 和我的 URL。我应该手动输入还是?现在,而不是 example.com,我希望它转到 127.0.0.1:8000。
    • 这里没有协议和域 {{ protocol }}://{{ domain }},它们存储在数据库中吗?
    • 是的,我明白了。谢谢老哥!!
    • 不要更改协议,它是自动的,可以是 http 或 https 或其他任何方式
    【解决方案2】:

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

    【讨论】:

    • 那么模板中真正的问题是视图周围缺少引号,以及 uid 后面的额外的 ',' 字符?
    • 只是一张便条,以确认 Derek 的回答和 winwaed 的评论。修复引号并删除评论是我的答案。 +1
    猜你喜欢
    • 2019-07-24
    • 2016-04-03
    • 2015-05-05
    • 2019-09-04
    • 1970-01-01
    • 2016-06-13
    • 2013-10-04
    • 2023-02-08
    • 2014-07-20
    相关资源
    最近更新 更多