How to run php in an HTML file running python?
I get an "unhandled ex开发者_如何学编程ception" every time I try to run this standard include in an html file running python:
<?php
//add header with tabs
include('includes/templates/common/tpl_header.php');
?>
I'm trying to run it right under the body tag that looks like this:
<body py:match="body" py:attrs="h.append_class_attr(attrs, 'mcore-body')" py:with="
attrs = h.attrs_to_dict(select('@*'));
body_class = attrs.get('class', '').split(' ');
advertising_banner_html = g.settings['advertising_banner_html'];
">
... sorry but I'm not the most avid programmer, how do you get that puppy to run?!
HTML is HTML, Python is Python and PHP is PHP.
It's THREE different technologies, which cannot be mixed.
You can't "run standard PHP include" in HTML file.
You can't "run standard PHP include" in Python file.
You can run PHP code in PHP file only.
You can't run Python code in HTML file. You can run Python code in Python file only.
So, whole question makes no sense.
It seems you should forget PHP while working with Python and use Python features for including files. Of course it shouldn't be PHP file, but Python or at least HTML file
You can't "run" PHP inside Pytho.
Genshi has xi:include
but that can include only local files.
It can apparently somehow be tricked into loading data from remote URLs - Here's an answer with some pointers (but no ready-made solution) how to do it.
If you manage to make Genshi fetch a remote file, you can point it to a local PHP URL: http://localhost/scripts/myscript.php
Be aware however that this will start a remote PHP instance, and probably be slower than a pure filesystem lookup.
I have been in this situation myself when customizing Trac installs. The workaround I always ended up using was having a PHP script run manually or frequently through a cron job, and write into a static file that can be included using xi:include
.
精彩评论