Answer the question
In order to leave comments, you need to log in
How to generate a link to a post?
Hello.
How can I generate a link for each blog post?
example.com/posts/*
Where * is from 1 to the number of posts.
I found this method:
But I did not understand how to fasten it. The console swears.
Answer the question
In order to leave comments, you need to log in
As far as I understand, this is because of the dot in post.id.
Name post_id for example.
Better yet, like this:
Guaranteed to pass only whole numbers.
Read more here:
flask.pocoo.org/docs/0.10/quickstart/#variable-rules
To generate links in flask there is a function url_for , it can be used both in code and in templates.
For such a route:
@app.route('/post/<int:post_id>')
def show_post(post_id):
return 'Post %d' % post_id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question