我在使用Pafy模块的Flask应用程序中有这个app.route:
@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)
然后呈现如下:
{% 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 %}
然而,文本仍然在所有数据周围显示单引号,例如:
Your video is now downloading
['Blur - Song 2', 'emimusic', '492,402', '78,314,578', '122']
我该如何删除?我尝试过strip(),replace()甚至是translator / maketrans而没有运气。
感谢
答案 0 :(得分:2)
加入清单
<form method="get">
FirstName<br>
<input type="text" name="fname"><br>
LastName<br>
<input type="text" name="lname"><br>
<a href="testpage.php"><input type="submit" name="sub" value="submit"></a>
</form>
然后在模板中放置video_details = ' '.join(video_details)