samedi 7 janvier 2017

Python as a replacement for PHP inside HTML

Is it possible to use Python for web development in the same way that PHP is used?

In other words, can I add some python code among my HTML that gets run on the server and possibly adds to the HTML?

For example, some PHP code:

<p>Cheese:</p> 
<ul>
<?php
    $cheeses = ['brie', 'cheddar', 'death star'];
    foreach ($cheeses as $c){
        echo "<li>".$c."</li>";
    }
?>
</ul>
<p>No more cheese :(</p>

Instead using python could be:

<p>Cheese:</p> 
<ul>
<?py
    cheeses = ['brie', 'cheddar', 'death star']
    for c in cheeses:
        print ("<li>" + c + "</li>")
?>
</ul>
<p>No more cheese :(</p>

Aucun commentaire:

Enregistrer un commentaire