Q:

trying to markup safe in flask/jinja2

how is the proper syntax to markup safe a variable when ever I try to substitute filename is get this when html is parsed
src="/static/%7B%7B%20car%7Csafe%20%7D%7D"
I'm using flask to pass in the variable to html
what am i doing wrong whats the proper syntax?
syntax i'm using is
src="{{url_for('static', filename='{{ car|safe }}')}}"

A:

You can easily link to a static file in 2 different ways.
1. Send the path of your file to your html template with a context:
In app.py:
from flask import Flask
from flask import render_template

web = Flask(__name__)

@web.route('/')
def example1():
    path_of_file='img/thisismyfile.jpg'
    return render_template('index.html',name_of_file = path_of_file)

if __name__ == '__main__':
    web.run()

In your html file (for example index.html):
<img src="{{url_for('static', filename=name_of_file)}}">

2. Just add your file path in HTML file:
<img src="{{url_for('static', filename='img/thisismyfile.jpg')}}">

