我正在尝试在 django 中激活用户帐户,但出现 404 错误,该错误是由于 django 无法获取激活 url 造成的。我正在尝试评估的链接是 http://127.0.0.1:8000/account/activate/MTU/anfs0f-046aa586847b91da0546e995f34c392a
,但我一直找不到 url。
django app urls.py
urlpatterns = [
path('account/', include('account.urls', namespace='account')),
]
================
urls.py
urlpatterns = [
path('activate/<slug:uidb64>/<slug:token>)/', views.account_activate, name='activate'),
]
views.py
def account_activate(request, uidb64, token):
try:
uid = force_text(urlsafe_base64_decode(uidb64))
user = UserBase.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.save()
login(request, user)
return redirect('account:dashboard')
else:
return render(request, 'account/registration/activation_invalid.html')
模板
{% autoescape off %}
Great {{ user.user_name }}!
Please click on the link below to activate your account
http://{{ domain }}{% url 'account:activate' uidb64=uid token=token %}
{% endautoescape %}
我花了几个小时试图找出我的错误在哪里,但我一直没能做到。请我对此有所了解。
答案 0 :(得分:1)
我认为您应该将您的 app_name 放在 urlpatterns 顶部的帐户 url 中。