goblin_rocket
goblin_rocket

Reputation: 377

How to remove single quotes from text in Flask template?

I have this app.route in a Flask app that uses the Pafy module:

@app.route('/result', methods = ['POST', 'GET'])
def result():
    if request.method == 'POST':
        video_url = request.form['url']
        video = pafy.new(video_url)
        video_title = video.title.strip('\'')
        video_author = video.author.strip('\'')
        video_likes = "{:,}".format(video.likes).strip('\'')
        video_views = "{:,}".format(video.viewcount).strip('\'')
        video_length = "{:,}".format(video.length).strip('\'')
        video_details = [video_title, video_author, video_likes, video_views, video_length]
        best = video.getbest(preftype="mp4")
        dl_video = best.download(quiet=False)


        return render_template('result.html', dl_video = dl_video, video_details=video_details)

this is then rendered as follows:

{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block body %}

<div class="jumbotron">

   <body>

   <h2>Your video is now downloading</h2>

   {% if dl_video %}


   {% endif %}

   {% if video_details %}

      <p> {{ video_details }} </p>

   {% endif %}

   </body>
</div>


{% endblock %}

however the text is still displayed with single quotation marks around all the data e.g.:

Your video is now downloading
['Blur - Song 2', 'emimusic', '492,402', '78,314,578', '122']

how can I remove this? I have tried with both strip(), replace() and even translator/maketrans with no luck.

thanks

Upvotes: 0

Views: 1942

Answers (1)

zabusa
zabusa

Reputation: 2719

join the list

video_details = ' '.join(video_details)

then put a {{video_details |safe }} in template

Upvotes: 4

Related Questions