Handle ampersand in a URL in Flask

Viewed 1821

I am new to web-development using Flask and Jinja2 templates. One column in a row of my HTML table in the template is:

<td><a> href="/plot?label={{stats[0]}}">{{stats[0]}} </a></td>

stats[0] is a variable which is a string and might contain an '&' e.g. "Eggs & Spam". Now in the view (views.py):

@app.route("/plot", methods = ["GET", "POST"])
@login_required
def on_plot():
    data = request.args
    label_name = data['label']

In this case I get data as ImmutableMultiDict([(' Spam', u''), ('label', u'Eggs ')]) which is not correct. Instead I want ImmutableMultiDict([('label', u'Eggs & Spam ')])

So how do I handle this case ? I tried doing {{stats[0]|escape}} but it doesn't work.

1 Answers
Related