Variable In Flask Static Files Routing [url_for('static', Filename='')]
I'm making a simple music app. I want to allow users upload their audio files and I have a page where I'm planning to show all songs. I've created a template, and the structure loo
Solution 1:
I don't believe you can nest template tags like that. But you also shouldn't need to.
<imgsrc="{{ url_for('static', filename='uploads/users/') }}{{ song['artistName'] }}/{{ song['pathToCover'] }}">
You can see why this works from the following example:
>>>from flask import Flask, url_for>>>app = Flask(__name__)>>>with app.test_request_context():...print url_for('static', filename='uploads/users/')
/static/uploads/users/
So then you just need to add the artistName
, /
, pathToCover
Solution 2:
I think you can do
<imgsrc="{{ url_for('static', filename='uploads/users/'+ song['artistName']+'/'+ song['pathToCover'])}}">
It works for me :)
Post a Comment for "Variable In Flask Static Files Routing [url_for('static', Filename='')]"