【问题标题】:how to pass account information to django template in django-registration?如何在 django-registration 中将帐户信息传递给 django 模板?
【发布时间】:2014-05-02 14:19:32
【问题描述】:

我想将account information 传递给template,这样当user account 被激活时,会出现一条消息“您的帐户已激活;请立即登录”,并带有下面的链接。如果activation days 已过期,则必须显示“激活天数已过期”。我这里有url和模板,但是不知道怎么把账号信息传给模板。

url.py

urlpatterns = patterns('',
                       url(r'^activate/complete/$',
                           TemplateView.as_view(template_name='registration/activate.html'),
                           name='registration_activation_complete'),
......)

registration/activate.html

{% extends "registration/base.html" %}

{% block title %}Account activated{% endblock %}

{% block content %}
  <h1>Account activated.</h1>
  {% load humanize %}
  {% if account %}
    <p>Thanks for signing up! Now you can <a href="/accounts/login/">log in</a>.</p>
  {% else %}
    <p>Sorry, it didn't work. Either your activation link was incorrect, or
    the activation key for your account has expired; activation keys are
    only valid for {{ expiration_days|apnumber }} days after
    registration.</p>
  {% endif %}
{% endblock %}

基本上,我想将accountexpiration_days 传递给上述模板。我只是不知道怎么做。请帮忙!

【问题讨论】:

    标签: django django-templates django-registration django-class-based-views


    【解决方案1】:

    恐怕像你一样使用TemplateView 是不够的;您必须编写一个自定义视图,其中将包含激活逻辑并将数据传递给模板。

    【讨论】:

      猜你喜欢
      • 2011-09-16
      • 2021-12-03
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      相关资源
      最近更新 更多