Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask render_template with url parameter

I use pdf.js to render pdf in web. The format of the target url like this:

http://www.example.com/book?file=abc.pdf

My problem is: I use flask template to generate page using:

return render_template('book.html', paraKey=paraValue)

But how to attach url parameter "file=abc.pdf" to url? The parameter will be read by viewer.js(included in book.html) that uses it to read file for rendering pdf.

I'm new to flask, hoping guys giving me some help!

like image 372
jayzhen Avatar asked Nov 17 '17 08:11

jayzhen


1 Answers

You could use redirect function, which can redirect you whatever you want:

@app.route('/book')
def hello():
    file = request.args.get('file')
    if not file:
        return redirect("/?file=abc.pdf")
    return render_template('book.html', paraKey=paraValue)
like image 166
Ivan Bryzzhin Avatar answered Oct 20 '22 00:10

Ivan Bryzzhin