php - Are there Django short tags for web development? If there are, how to enable it?

602

Example of native PHP code:

<h1><?php echo "Hello world!"; ?></h1>

Example of PHP short tags:

<h1><? echo "Hello world!"; ?></h1>

Are there Python code that looks like this:

<h1><% print "Hello world!"; %></h1>

If there are, how to enable that?

43

Answer

Solution:

Generally Python works a little bit different to PHP. You need a template engine to do that. See: https://wiki.python.org/moin/Templating

369

Answer

Solution:

A big yes. The tags in Django look like this:

<p>{{ this_is_a_variable }}</p>
{% for letter in 'This is a statement' %}
    <p>{{ letter }}</p>
{% endfor %}

Django is a very good framework, unlike anything I have ever seen (part of it is because Python is a great language!)

You can't execute arbitrary code here, but take it as an advantage: you will respect MVC better

People are also looking for solutions to the problem: php - Redirect Message Symfony

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.