João A. Veiga
João A. Veiga

Reputation: 577

Jinja2 HTML templates use multiple nested quotation marks (" and ')

The question is simple, I am using jinja2 html templates and I am supposed to include {{ url_for('static', filename='img/background.png') }} inside of url(''), inside of style="".

The proble is that there is a quotation mark conflict, because there are two nested ' marks

<body id="body-pd" style="background: url('{{ url_for('static', filename='img/background.png') }}') no-repeat center center fixed; background-size: cover;">

Is there some sort of scape character to be used?

Upvotes: 0

Views: 507

Answers (1)

Dauros
Dauros

Reputation: 10577

The answer to this problem is also very simple: there's no problem. The Jinja environment (server side) and browser/frontend environment have different lifecycle.

Jinja only sees this part:

{{ url_for('static', filename='img/background.png') }}

It produces a path, e.g. /static/img/background.png and replaces the whole {{ ... }} snippet with it. The frontend environment never sees Jinja-related parts. So there's no quotation mark conflict, because half of them will be eliminated by Jinja on the server side.

Upvotes: 2

Related Questions