How to decode a url string in a flask template


I am using flask.

In my template I used this to encode a string.


Now I want to decode in another template.
Where is what the string looks like.


In the template how do I decode the string?

{% for crid, object in tag_handler.iteritems() %}
    <script>var x = decodeURI("{{object['tag_display']}}"); alert(x);</script>
        <div id="tagBox" style="display: block;width: 700px">
            <pre class="prettyprint">
                <code class="language-html">    

{% endfor %}

I am using google pretty to display the string.

9/5/2013 7:24:25 PM

You can use Python's urllib. There are a couple of options, unquote and unquote_plus. See for explanation. In brief, "Choose unquote_plus if your URLs use ‘+’ for spaces, and remember that HTML forms do this automatically."

from urllib import unquote_plus
@app.route('/foo', methods=['POST'])
def foo():
    mytag = request.form['params']
    print unquote_plus(mytag)
2/23/2016 12:12:33 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow