PHP within HTML not working using Flask PHP within HTML not working using Flask flask flask

PHP within HTML not working using Flask


You would not use PHP in Flask. If you want some scripting logic in your template, use something like this:

<html><head></head><body><ul>{% for i in range(1,6) %}<li>Menu Item {{ i }}</li>{% endfor %}</ul></body></html>


Answer to question by Matt Healy is right.

But looking at your code I seem problem it should be like this

<ul>  <?php     for($i=1;$i<=5;$i++){       echo "<li>Menu Item ".$i."</li>";     }  ?></ul>

And make sure you have .php as the file extension. Because Php will not run in HTML file.


The PHP interpreter does not work the way you want to use it.You are calling the HTML (template) file from within a flask app, thus not using the PHP interpreter.You best stick to PHP with supportet templating eg. smarty, or go for Pythonic. Trying mixing the two is a bad idea.