flask render_template with url parameter
You can get the parameter that have been passed in the request url by using the request object.
@app.route("/book", methods=["GET"]) def get_book(): file = request.args.get("file") if file: return render_template('book.html', file=file) abort(401, description="Missing file parameter in request url")
This topic helped me reslove my question, but it seems not the perfect answer.code viewer.py not changed.Solution is:
step1)I embed the code
<script>var FILE_PATH = {{ file }}</script>
in template.
step2)the script that will use the variable need to modify the code(viewer.js),from:
var file = 'file' in params ? params.file : DEFAULT_URL
to
var file = FILE_PATH ? FILE_PATH: DEFAULT_URL
It let viewer.js not independent anymore.
I hope someone provide a better solution.