views.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:beg-django-e-commerce 作者: Apress 项目源码 文件源码
def activate(request, activation_key,
             template_name='registration/activate.html',
             extra_context=None):
    """
    Activate a ``User``'s account from an activation key, if their key
    is valid and hasn't expired.

    By default, use the template ``registration/activate.html``; to
    change this, pass the name of a template as the keyword argument
    ``template_name``.

    **Required arguments**

    ``activation_key``
       The activation key to validate and use for activating the
       ``User``.

    **Optional arguments**

    ``extra_context``
        A dictionary of variables to add to the template context. Any
        callable object in this dictionary will be called to produce
        the end result which appears in the context.

    ``template_name``
        A custom template to use.

    **Context:**

    ``account``
        The ``User`` object corresponding to the account, if the
        activation was successful. ``False`` if the activation was not
        successful.

    ``expiration_days``
        The number of days for which activation keys stay valid after
        registration.

    Any extra variables supplied in the ``extra_context`` argument
    (see above).

    **Template:**

    registration/activate.html or ``template_name`` keyword argument.

    """
    activation_key = activation_key.lower() # Normalize before trying anything with it.
    account = RegistrationProfile.objects.activate_user(activation_key)
    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value
    return render_to_response(template_name,
                              { 'account': account,
                                'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
                              context_instance=context)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号