What dose the curly-brace and percent sign mean in html?

14,148

First and foremost, the correct tags for the Django template language are {% %}, and not <? ?>.

And you're correct that this is a part of Django. This is an example of a domain specific language, which, as the Wikipedia says, is a language invented for a particular task. In this case, the Django templating language is built to handle, well, templates.

It works because Django comes with a parser to interpret the language and make sense of it. A parser takes a string that might otherwise has no meaning in HTML or any other language, such as {% block pasta %} and converts it into something meaningful. In this case it ultimately outputs HTML.

It happens that you could write your own parser in any language to interpret the Django templating language, or even write a new language entirely. But the difficulty of such a task increases as your language gets more complex, and also hinges on the language you choose. PHP is notoriously bad at parsing, while other languages like Perl are known to be better at it. In general it's much easier to just run a search and use a pre-built parser instead of re-inventing the wheel. Though that of course is a lot less fun way to go about it :)

p.s. This might be of interest to you.

Share:
14,148
Roy Li
Author by

Roy Li

Updated on July 17, 2022

Comments

  • Roy Li
    Roy Li almost 2 years

    I am learning how to develop website in Django framework. There is something I don't understand about the template html file.

    I saw the tutorial used the curly-braces(<% if ... %> <% endif %> etc.) to embed logic in the code. But when I try to use this syntax in a non-Django server(Apache) this syntax was not interpreted and I can see my <% if ... %> ... right on my page.

    I dont know why this is.

    So this syntax is not a part if HTML but rather a part of Django so it can be interpreted by it?

  • jamesplease
    jamesplease about 11 years
    True, true. But otherwise my answer is correct, yes? I'll add a note to him that the tags he used above aren't quite right.