I've been developing a site to be able to curate sports media using Django, and that's going reasonably well, but my friend that I'm working with has some of our required functionality (some information display, page-level stuff) going with PHP. Is there an easy way to integrate those, like maybe running the php through the Django templates, or should we try and convert some the functions to one language or the other?
我一直在开发一个网站,以便能够使用Django来管理体育媒体,这个网站运行得相当不错,但是我的朋友在使用PHP时拥有一些我们需要的功能(一些信息显示,页面级的东西)。是否有一种简单的方法来集成它们,比如通过Django模板运行php,或者我们是否应该尝试将一些函数转换成一种或另一种语言?
2 个解决方案
#1
1
In such cases, I think, it makes sense to make some kind of internal interface through which your sites would communicate, and expose only one of them to public. That would make everything more maintainable.
在这种情况下,我认为,建立某种内部接口是有意义的,您的站点可以通过这种接口进行通信,并且只公开其中的一个。这将使一切更易于维护。
For example, your friend can make his PHP pages to output information in JSON or YAML. In corresponding Django views, you'll have little to no logic, just making internal HTTP requests to these pages, and basically passing the data to templates.
例如,您的朋友可以使用PHP页面输出JSON或YAML中的信息。在相应的Django视图中,几乎没有逻辑,只需向这些页面发出内部HTTP请求,并将数据传递给模板。
This way, you'll have output via Django templates, and some logic still in PHP. If PHP code does some work with database or performs computation that can't be converted easily enough to Python, and you have limited time, this option may be the best.
这样,您将通过Django模板获得输出,并且在PHP中还有一些逻辑。如果PHP代码处理数据库或执行不能很容易地转换为Python的计算,并且您有有限的时间,这个选项可能是最好的。
Though, I guess, it depends a lot on the architecture of the project, especially the PHP part. There's not enough information to say what's the best option for you.
尽管如此,我认为这在很大程度上取决于项目的体系结构,尤其是PHP部分。没有足够的信息告诉你什么是对你最好的选择。
#2
1
Don't mix languages if you have any other option. Honestly, I don't think the type of integration you're imagining is even possible. About the closest you would ever get would be two separate websites that shared a common look and feel and passed info back and forth to each other. At the end of the day, though, there would always be a separation of management and data.
如果有其他选择,不要混合语言。老实说,我不认为你想象的那种整合是可能的。你能找到的最接近的是两个独立的网站,它们共享相同的外观和感觉,并相互传递信息。不过,到最后,管理和数据总是要分开的。
There's some pretty robust PHP frameworks out there. Assuming your friend is using one of those, you'll need to decide which best fits with the time and skills you both have to devote to the project. If your friend is not using a framework, the decision is simple: move everything over to Django.
有一些非常健壮的PHP框架。假设你的朋友正在使用其中的一种,你需要决定哪一种最适合你和你的朋友投入到项目中的时间和技能。如果您的朋友没有使用框架,那么决定很简单:将所有内容转移到Django。
#1
1
In such cases, I think, it makes sense to make some kind of internal interface through which your sites would communicate, and expose only one of them to public. That would make everything more maintainable.
在这种情况下,我认为,建立某种内部接口是有意义的,您的站点可以通过这种接口进行通信,并且只公开其中的一个。这将使一切更易于维护。
For example, your friend can make his PHP pages to output information in JSON or YAML. In corresponding Django views, you'll have little to no logic, just making internal HTTP requests to these pages, and basically passing the data to templates.
例如,您的朋友可以使用PHP页面输出JSON或YAML中的信息。在相应的Django视图中,几乎没有逻辑,只需向这些页面发出内部HTTP请求,并将数据传递给模板。
This way, you'll have output via Django templates, and some logic still in PHP. If PHP code does some work with database or performs computation that can't be converted easily enough to Python, and you have limited time, this option may be the best.
这样,您将通过Django模板获得输出,并且在PHP中还有一些逻辑。如果PHP代码处理数据库或执行不能很容易地转换为Python的计算,并且您有有限的时间,这个选项可能是最好的。
Though, I guess, it depends a lot on the architecture of the project, especially the PHP part. There's not enough information to say what's the best option for you.
尽管如此,我认为这在很大程度上取决于项目的体系结构,尤其是PHP部分。没有足够的信息告诉你什么是对你最好的选择。
#2
1
Don't mix languages if you have any other option. Honestly, I don't think the type of integration you're imagining is even possible. About the closest you would ever get would be two separate websites that shared a common look and feel and passed info back and forth to each other. At the end of the day, though, there would always be a separation of management and data.
如果有其他选择,不要混合语言。老实说,我不认为你想象的那种整合是可能的。你能找到的最接近的是两个独立的网站,它们共享相同的外观和感觉,并相互传递信息。不过,到最后,管理和数据总是要分开的。
There's some pretty robust PHP frameworks out there. Assuming your friend is using one of those, you'll need to decide which best fits with the time and skills you both have to devote to the project. If your friend is not using a framework, the decision is simple: move everything over to Django.
有一些非常健壮的PHP框架。假设你的朋友正在使用其中的一种,你需要决定哪一种最适合你和你的朋友投入到项目中的时间和技能。如果您的朋友没有使用框架,那么决定很简单:将所有内容转移到Django。