[Python] Python as a replacement for PHP inside HTML

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    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>

    Continue reading...

Compartilhe esta Página