Built-in PHP tags for Python?

I'm just starting to learn python (for using Webapp), but I'm confused about the best way to use it with html files and dynamic data. I know php has tags <?php ?>that are good - python has something similar or equivalent, if not, how should I do it?

+3
source share
4 answers

PHP inline tags actually tend to encourage bad practice, namely, mixing your control logic (PHP code) with your templates (html). Most Python frameworks tend to avoid this combination and instead encourage separation between them - usually using some kind of template system .

Many frameworks have their own template systems (for example, the Django template system is quite popular). Others do not allow and allow you to choose a separate template engine (for example, Cheetah ).

+6
source

python php. Mod_python , spyce - , pythonistas. . Genshi jinja2 , .

- python, , , . , Django, . , -, .

+4

, Python : Python (a.k.a. psp), mod_python. , :

<html>
 <% import time %>
 Hello world, the time is: <%=time.strftime("%Y-%m-%d, %H:%M:%S")%>
</html>

, , . - Python. web2py , . bottle, flask cherrypy . Django, TurboGears , .

+2

, Python Server Pages (psp), PHP, mod_python, psp Apache:

<Directory /var/www/html>
    AddHandler mod_python .psp
    PythonHandler mod_python.psp
    PythonDebug On
</Directory>

test.psp .: -)

<html>
<% import time %>
Hello world, the time is: <%=time.strftime("%Y-%m-%d, %H:%M:%S")%>
</html>

But, unfortunately, mod_python resigned , and you should use mod_wsgiand, unfortunately, "there is no port mod_python PSP for mod_wsgi" .

0
source

Source: https://habr.com/ru/post/1762196/


All Articles