简体   繁体   English

如何在现有的Django Web应用程序之上集成wordpress前端

[英]How can I integrate a wordpress front-end on top of my existing Django web application

I have built a new website using wordpress which looks great and has required blogging functionality. 我使用wordpress构建了一个新网站,它看起来很棒并且需要博客功能。

Our old site was built using Django and looked awful but had required backend functionality built into it thanks to Django. 我们的旧网站是使用Django构建的,看起来非常糟糕,但由于Django,它需要内置后端功能。 For example on one page it has a drop down box and you select options from it and it returns data, which works fine on the Django website. 例如,在一个页面上它有一个下拉框,你从中选择选项并返回数据,这在Django网站上运行正常。

I want to integrate this functionality into the wordpress front-end somehow. 我想以某种方式将此功能集成到wordpress前端。 Is this possible? 这可能吗? If so can you suggest how I might do this? 如果是这样,你能建议我怎么做吗?

I understand that wordpress is a PHP CMS, and Django is a Python framework so you can't simply click them together. 我知道wordpress是一个PHP CMS,而Django是一个Python框架,所以你不能简单地将它们一起点击。 But does anyone have any suggestions on how I might integrate the functionality from my existing Django website inside my wordpress front end. 但是有没有人对如何在我的wordpress前端集成现有Django网站的功能有任何建议。

I have found this question: Wordpress on Django 我发现了这个问题: Django上的Wordpress

Which asked how to connect to wordpress from Django. 其中提到了如何从Django连接到wordpress。 But I would like to connect to Django from wordpress. 但我想从wordpress连接到Django。

In essence I want to replicate some of the Django pages on my wordpress site, utilising the existing Django backend functionality. 本质上我想利用现有的Django后端功能在我的wordpress网站上复制一些Django页面。

Can this be done? 可以这样做吗? Any suggestions as to how? 有关如何的任何建议?

Thanks. 谢谢。

I will share my experience in creating a hybrid solution and although for me it was two different PHP frameworks the approach could be the same. 我将分享我在创建混合解决方案方面的经验,虽然对我来说这是两种不同的PHP框架,但这种方法可能是相同的。 It's not a ready-to-go solution, but maybe it will help. 它不是一个随时可用的解决方案,但它可能会有所帮助。 I will list key points. 我将列出关键点。

  1. To have both Wordpress and django on the same url you have to install them on the same webserver (Apache most likely) 要在同一个URL上同时使用Wordpress和django,您必须在同一个Web服务器上安装它们(Apache最有可能)
  2. Put django app and Wordpress site in different folders eg localhost/wordpress and localhost/django so that rewrite rules do not interfere. 将django app和Wordpress站点放在不同的文件夹中,例如localhost/wordpresslocalhost/django这样重写规则就不会干扰。
  3. Write a Wordpress plugin that will store the session in the database (there are tutorials on the web, but the main idea is to implement session save/load functions and use session_set_save_handler() to register them) 编写一个Wordpress插件,将会话存储在数据库中(Web上有教程,但主要思想是实现会话保存/加载功能,并使用session_set_save_handler()进行注册)
  4. Write a Worpdress plugin that will add menu points for all your old backend functions (or just one menu saying "Backend") 编写一个Worpdress插件,为所有旧的后端功能添加菜单点(或者只是一个菜单说“Backend”)
  5. Whenever user clicks this menu simply redirect him to the localhost/django/oldfunction 每当用户单击此菜单时,只需将其重定向到localhost/django/oldfunction
  6. In django app - read the PHPSESSID from cookies, and use it to read additional session data from the database (user_id for instance) and create a session. 在django app中 - 从cookie中读取PHPSESSID ,并使用它从数据库中读取其他会话数据(例如user_id)并创建会话。 That way you implement "Single Signon" between two apps. 这样你就可以在两个应用程序之间实现“单点登录”。
  7. Adjust css-styles in django so that UI-controls in old app looks similar to the new site. 调整django中的css样式,以便旧应用程序中的UI控件看起来与新站点类似。 That has to be done manually in most cases. 在大多数情况下,这必须手动完成。 The target is to make an impression this is one app. 目标是给人留下印象,这是一个应用程序。 In my experience it's enough to adjust color-scheme of the UI controls, the rest doesn't matter that much. 根据我的经验,它足以调整UI控件的颜色方案,其余的并不重要。

This is a complicated approach and it's not fast but it's clean (you have two independent apps) and potentially allows slowly migrating and refactoring the old app functions into new one. 这是一个复杂的方法,它并不快,但它很干净(你有两个独立的应用程序),并可能允许慢慢迁移和重构旧的应用程序功能到新的。 The main thing here to have the access to the same database from both apps and to have them hosted on the same webserver. 这里的主要任务是从两个应用程序访问相同的数据库,并将它们托管在同一个Web服务器上。

Have you tried, https://github.com/agiliq/django-wordpress ? 你试过吗, https://github.com/agiliq/django-wordpress

I haven't used it yet. 我还没用过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM