使用多个应用程序处理 django 身份验证

Handling of django authentication with multiple apps

无法从当前的 SO 问题中找到简单问题的解决方案。

我在一个 django 项目中有 2 个应用程序。
App1 来自图教程here
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,它会将 accounts/login/ 添加到 url,因为这是默认值。

当请求在 Login_Required 装饰器后面时,对于其他应用程序中发出的任何请求,App1 中的函数处理 login/logout 请求是什么我不理解?为什么它不检查我是否已经通过身份验证,如果我没有 @Login_Required 装饰器并在页面之间移动,它会保留我的 name/email/calendar 调用。

谢谢

我联系了 Django 项目的支持团队。
一位维护者查看了我的源代码,我这边看起来一切都很好,他还检查了我在问题中提供的教程 link。

    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/