英文:
How can I restrict a user from accessing certain pages?
问题
以下是翻译好的部分:
有页面 "password_reset/" 和 "password_reset/done/"。在 "password_reset/" 页面填写表单后,会重定向到 "password_reset/done/" 页面。但如果有人尝试通过 URL 访问该页面,他将成功。如何修复它。
我尝试以以下方式解决,但某些地方没有成功。
class CustomPasswordResetDoneView(PasswordResetDoneView):
def get(self, request, *args, **kwargs):
referer = request.META.get('HTTP_REFERER')
if referer != reverse('password_reset'):
return HttpResponse(status=404)
return render(request, 'registration/password_reset_done.html')
希望这有所帮助。如果您需要更多信息,请随时提出。
英文:
There are pages "password_reset/" and "password_reset/done/". After filling out the form on the "password_reset/" page, there is a redirect to the "password_reset/done/" page. But if someone tries to access the page through the url, he will succeed. How to fix it.<br>
path('password_reset/', views.PasswordResetView.as_view(), name='password_reset'),
path('password_reset/done/', views.PasswordResetDoneView.as_view(), name='password_reset_done'),
I tried to solve it this way, but something didn't work out.<br>
class CustomPasswordResetDoneView(PasswordResetDoneView):
def get(self, request, *args, **kwargs):
referer = request.META.get('HTTP_REFERER')
if referer != reverse('password_reset'):
return HttpResponse(status=404)
return render(request, 'registration/password_reset_done.html')
答案1
得分: 1
你可以通过使用 Mixins、装饰器或 is_user_authenticated 来实现这一点。
英文:
You can do this by using Mixins, Decorators or is_user_authenticated.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论