0

I've started using the Flask Python framework, and I'm having trouble getting indentation to work properly in the template .html files. I use web-mode, and it seems to really not want me to indent without opening a new html tag. For instance, this is the default indentation:

<!-- extend base layout -->
{% extends "base.html" %}

{% block content %}
<h1>Sign in</h1>
<form action="" method="post" name="login">
    {{ form.hidden_tag() }}
    <p>
        Please enter your OpenID:<br>
        {{ form.openid(size=80) }}<br>
        {% for error in form.openid.errors %}
        <span style="color: red;">[{{ error }}]</span>
        {% endfor %}
    </p>
    <p>{{ form.remember_me }} Remember me</p>
    <p><input type="submit" value="Sign in"></p>
</form>
{% endblock %}

Ideally I would indent code within the for loop so that I can more clearly view the structure of my code, but web-mode won't let me Tab that line over, no matter how many times I try. I couldn't find any other packages for Flask, but maybe I'm in the wrong place. Is there a way to get web-mode and Flask to play nicely?

2

You can call the web-mode-set-engine command from M-x this will allow you to set which template you want to use. The engine that you want it "django" (yes even though you are using flask/jinja).

You can also set the variable web-mode-engines-alist such as:

(setq web-mode-engines-alist
             '(("php" . "\\.phtml\\'")
               ("jinja" . "\\.djhtml\\")))

This will make any file that I have open that matches the regexp on the right side use the engine on the left. The regexp can be anything this is simply my config.

If you have any questions or I wasn't clear ask away

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.