将 django 与旧版身份验证 cookie 一起使用
我在自制 python 框架中有一个大型代码库。我将逐步将代码转移到 Django,但同时需要支持通过旧系统登录。旧系统在用户登录后使用 cookie 来识别用户。
我不希望用户通过 Django 登录,但我确实希望能够使用 @login_required 以及依赖于 Django 身份验证系统的几个应用程序,例如 admin、django-tagging 和 django-comments。
集成两个身份验证系统的最佳方法是什么?两个代码库都在同一个 python 进程中运行(通过根据请求切换应用程序的 wsgi 中间件),并且可以根据需要相互加载模块。
I have a large codebase in a homebrew python framework. I'm going to be gradually moving the code to Django, but in the meantime need to support logging in via the old system. The old system uses a cookie to identify the user after they have logged in.
I don't want users to log in via Django, but I do want to be able to use @login_required as well as several apps that rely on Django's auth system, such as the admin, django-tagging and django-comments.
What's the best way to integrate the two auth systems? Both codebases are running within the same python process (via a wsgi middleware that switches apps per-request) and can load modules from each other as needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让它工作的最简单方法可能是在 Django 中使用自定义身份验证中间件。
Django 中有几个示例身份验证中间件: http: //code.djangoproject.com/browser/django/trunk/django/contrib/auth/middleware.py
The easiest way to get it working is probably to use a custom authentication middleware in Django.
There are a couple of example authentication middlewares in Django: http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/middleware.py