Writing Indent in django Template with vim

  question, vim

When using vim django templates, for example:

<li>
    {% if sth %}
        <p>something</p>
    {% endif %}
</li>

The indent I requested is the same as above, but in vim, the line “< p >” will be forced to indent forward automatically and become:

<li>
   {% if sth %}
   <p>something</p>
   {% endif %}
</lil>

The line “< p >” must be lost and indented manually. .

What I understand is that because this is an html file, vim treats it as a normal html indent format, ignoring the if tag in django.
So what should we do to make vim treat “{%}” as a tag in html?

Can I consider {% if * %} and < li > in your code to be of the same grade? Or the following writing method is more in line with the requirements and will not damage the indented structure of HTML.

<li>
{% if sth %}
    <p>something</p>
{% endif %}
</li>