为 Django 项目(通过 cgi 运行)制作 PHP 前端的有效方法是什么?

发布于 2024-09-18 07:39:19 字数 335 浏览 4 评论 0原文

我想在 Django 中开发一个网站,拥有方便的 ORM 和管理功能,以简化管理。

然而,我唯一的托管选项是通过CGI运行Django。因此,我还想用 PHP 制作一个“只读”前端,这将使日常使用体验变得“正常”(即仅编辑[数据库],并且通过 Django/admin 进行身份验证)。

什么是有效的方法(如果有的话)来最大化(总体感知的)性能,特别是在 PHP 前端和 Django 之间的身份验证方面?

I want to develop a site in Django, to have the convenient ORM, and admin, to ease administration.

However, the only hosting option I have is running Django through CGI. Therefore, I would also like to make a "read-only" front end in PHP, which will make the experience "normal" for everyday use (i.e only editing [the database] and authentication will be done through Django/admin).

What is an efficient approach (if there is any), to maximize the (overall percieved) performance, especially with regards to authentication across the PHP front end and Django?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思故 2024-09-25 07:39:19

基本上,您想使用 Django 进行管理员和用户身份验证。正确的?

那应该没问题。实际上,这与我现在正在做的事情有关,因为我们正在将旧版 PHP 网站(活跃,每天有数千人使用)与使用 Django 的新功能混合在一起。

我之前曾使用过 Django,只是为了管理,效果很好。我在 MySQL 中手动设置数据库表,并通过 PHP 中的 PDO 像平常一样访问它们。我在 Django 模型中复制了架构,并设置了管理 - 它工作得很好。

认证更加困难。我们也在这样做。我实际上发现了这个问题,因为我正在寻找其他人的经验!

我认为最好的方法是当用户通过 Django 登录时将登录用户的 ID 存储在 cookie 中。加密cookie,您可以在PHP中获取ID和/或其他信息。注销时删除 cookie,然后一切就都准备好了。不幸的是,您将无法使用 Django 会话。不过,您可以将其与 PHP 会话联系起来。

无论如何,我看到这个问题是不久前的事了。如果您自己解决了这个问题,请回来查看并告诉我们结果如何!

Basically, you want to use Django for the admin and user authentication. Correct?

That should work okay. It's about what I'm doing now, actually, as we're mixing a legacy PHP site (active, used by thousands every day) with new features that use Django.

I have used Django before just for the admin and it works great. I set up the DB tables manually in MySQL, and accessed them like normal through PDO in PHP. I duplicated the schema in a Django model, and set up the admin - it works perfectly.

Authentication is tougher. We're doing that too. I actually found this question because I was looking for others experiences with that!

I think the best way to do it is to just store the ID of a logged in user in a cookie when a user signs in through Django. Encrypt the cookie, and you can get the ID and/or other information in PHP. Delete the cookie on sign out, and you should be all set. Unfortunately you won't be able to use Django sessions. You could tie this to PHP sessions, though.

Anyhow, I see this question was a while ago. If you solved this for yourself, please check back and let us know how it went!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文