NoReverseMatch at / signup /

时间:2018-04-13 06:55:39

标签: python django

Reverse for 'activate' with keyword arguments '{'uidb64': b'Mw', 'token': '4vb-698f794fd74543e1258f'}' not found. 1 pattern(s) tried: ['activate/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$']

模板/ account_activation_email.html

{% autoescape off %}
Hi {{ user.username }},

Please click on the link below to confirm your registration:

http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
{% endautoescape %}

它似乎在我的localhost网址上正常工作;但是当它在heroku中瘫痪时。它抛出了这个错误。

views.py

def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None

    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.profile.email_confirmed = True
        user.save()
        login(request, user)
        return redirect('home')
    else:
        return render(request, 'account_activation_invalid.html')

urls.py

url(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
        core_views.activate, name='activate'),

1 个答案:

答案 0 :(得分:0)

'uidb64': b'Mw'

这是byte code,但django需要string

所以在view发送uid

的地方

执行decodeuid.decode('utf-8')

然后将其发送到模板