Prevent Jinja expressions ({{ }}) from aligning


PyCharm aligns Jinja expressions ( {{ }} ) whenever I paste code or run Reformat Code. While this is might be useful in some cases it is not when the expression is part of an URL as the aligning breaks it and makes the referenced resource unreachable, see the image below.

I need everything in content="" to be on the same line.


How can I control/disable this behaviour?


I currently can't paste code or use Reformat Code as I have to manually restore the URLs afterwards.

I browsed all the options in Settings -> Editor -> Code Style -> HTML but none of them seem to control this behaviour.


Kind regards,


Comment actions Permalink


What is your PyCharm version?

I can't reproduce that behaviour in 2019.2.1. Only is reproducible.

Comment actions Permalink

Hi Sergey,

thanks for the quick reply!

I'm using PyCharm 2019.2.2 (Professional Edition)
Build #PY-192.6603.34, built on September 10, 2019

I think I found the cause of my problem: the lines are wrapped as I described only if they are longer than the "Hard wrap" value in Settings -> Editor -> Code Style. Shorter lines are not wrapped and setting Hard wrap to e.g. 500 "fixes" the problem.


Is there a way to turn wrapping (on HTML files) off or is increasing the Hard wrap value The Fix?


PS it seems that the issue you link to is fixed in 2019.2.2 since I can't reproduce it.

PPS Note that Settings -> Code Style -> HTML -> Other tab -> Hard wrap at value does not have an effect on Reformat Code. Setting it at e.g. 500 results in a wrapped lines. 

Comment actions Permalink

Hmm, I still can't reproduce it.

It just moves that line to the next line and hence making it less than default 120 hard wrap. Making it longer results in the mentioned above bug with empty lines.

{{ config['FULL_URL'] }}{{ config['URL_TO_IMAGE_FILES'] }}{{ config['USR_IMAGE_FOLDER'] }}{{ post['image'] }}">

Would it be possible to share some project for reproducing?
You can upload it to our FTP server, but please let me know the name of the file so I can find it.

Comment actions Permalink

> It just moves that line to the next line and hence making it less than default 120 hard wrap.

For me it moves it by terminating the line and adding a number of spaces at the beginning of the next line, see the grey areas in the screenshot below at the end of and beginning of line 15 and 16, respectively.

The line break and spaces are encoded as %0A and %20 characters in the URL making it reference a non-existing resource. Result: links fail to resolve and images fail to load.

It might be that I'm experiencing the same bug but as I said earlier I can't reproduce it.

Comment actions Permalink

Do you use some 3rd party plugins?

Is it reproducible in a new test project?


Please sign in to leave a comment.