Issue
In my flask app i have these codes:
from __main__ import app
@app.context_processor
def breakline():
return { 'break': '<br>' }
How to use in html format is as follows:
{{ break }}
The above code works but there is a problem; A safe
filter is needed to detect <br>
; But I do not want to be added in html format every time like this:
{{ break | safe }}
I want this safe
filter to be applied automatically and no longer need to be used in the html page. Is such a thing possible?
This is just an example and I do not just want to be able to create a <br>
. I want to know if a filter can be added to a context_processor or not.
Solution
You can mark your html code as safe by using Markup.
from flask import Markup
@app.context_processor
def breakline():
return { 'break': Markup('<br>') }
Answered By - Detlef
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.