Integrate a Python Application into a PHP Website

It may seem really crazy, but still ...

For our updated project site, we want to integrate Trac (as a code browser, developer wiki and release tracker) into the site design. This, of course, is difficult because Trac is written in Python and our site in PHP. Does anyone know how to integrate the header and footer (PHP) into the Trac template (preferably without invoking the command line, or rather two for the header and footer)?

+4
source share
3 answers

The best option is probably to (re) write the header and footer using python.

If the headers and footers are relatively static, you can also generate them once with php (or once every x minutes) and include them from the file system. (You probably already thought about it and rejected this idea because your sites are too dynamic to use this option?)

Although I would not recommend it, you can also use some form of AJAX to load parts of the page, and nothing prevents you from loading this content from a php based system. This can lead to all parts being dynamic. Your pages will probably look ugly on loading, and now you will create more requests on the server than you need, but if it is a large site, it can be large.

Warning. If you have user logins on both systems, you are likely to run into problems when people can only log in to half of your site.

+1
source

Abstraction is your friend.

Isolate raw HTML from your PHP header and footer in a simple template language, if possible, and write Python and PHP interfaces to your template language. Or repeat the work that other people have done. This diagram shows that the Template Attribute Language (TAL) supports Python and PHP5.

+1
source

Your Python code will have access to your users cookies. A template would be better, but if you don’t have one available (or the header / footer is trivially small or something else), you can simply transfer the PHP header and footer code to Python using cookies that already exist to request the base data or whatever you need to do.

If you want to save your links for logging in, registering and what else might be in the PHP version, just a link to the PHP side, and then redirect back to Trac as soon as PHP does its job.

0
source

All Articles