无法从当前的 SO 问题中找到一个简单问题的解决方案。
我在 django 项目中有 2 个应用程序。
App1 来自此处找到的图形教程
App2 将允许用户从数据库中列出数据,在这种情况下它将是分支名称。
如果我尝试使用 @login_required 装饰器访问页面,则 url 路由添加了 /accounts/login/ 并且我得到通常的无法找到错误。
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/accounts/login/?next=/calendar
Using the URLconf defined in graph_project.urls, Django tried these URL patterns, in this order:
[name='home']
about [name='about']
signin [name='signin']
signout [name='signout']
calendar [name='calendar']
callback [name='callback']
branches/
admin/
branches/
The current path, accounts/login/, didn't match any of these.
如果我正确阅读了 django 文档,那么这是默认设置,我可以使用项目设置中的 LOGIN_URL 重定向登录路径。当我将其设置为 App1 教程中创建的登录功能时
def sign_in(request):
# Get the sign-in URL
sign_in_url, state = get_sign_in_url()
# Save the expected state so we can validate in the callback
request.session['auth_state'] = state
# Redirect to the Azure sign-in page
return HttpResponseRedirect(sign_in_url)
它将永远循环 MS OAuth 登录,但一旦完成就永远不会访问请求的页面。如果我从设置中省略 LOGIN_URL,它会将帐户/登录/添加到 url,因为这是默认设置。
当请求位于 Login_Required 装饰器后面时,对于其他应用程序中发出的任何请求,我不理解 App1 中的函数处理登录/注销请求是什么?如果我没有 @Login_Required 装饰器并在页面之间移动,为什么当我可以看到它保存我的姓名/电子邮件/日历调用时,它为什么不检查我是否已经通过身份验证。
谢谢
我联系了 Django-Project 的支持团队。
其中一位维护者查看了我的源代码,在我看来一切都很好,他还检查了我在问题中提供的教程链接。
His exact words were
>Personally, I’m a bit suspicious with how they’re doing this. I’ve read through the >tutorial and it looks to me like they’ve taken some shortcuts with managing the user in >the session.
That is enough for me to drop that route and look somewhere else, he offered these as a suggestion should anyone care to look into what I moved on to using.
[Azure AD pypi][1]
[Django Auth Docs][2]
[MS Django Auth][3]
[1]: https://pypi.org/project/django-azure-ad-auth/
[2]: https://django-auth-adfs.readthedocs.io/en/latest/
[3]: https://pypi.org/project/django-microsoft-auth/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句