My problem is I can hardcode the links but when I do it dynamically, I just get an error
@app.route('/posts/<string:id>')
def show_post(id):
# Retrieve the post with the specified id
# You can replace this with a database query to fetch the post
database = db.child("contents").get()
posts.clear()
for title in database.each():
posts.append(title.val())
count = 1
newposts = {
}
#nposts = posts
for post in posts:
newposts.update({str(count): post})
count+=1
newposts.get(id)
sus = newposts.get(id)
print(url_for('posts'))
#postid = newposts.get(id)
if newposts:
# Return the post with the specified id
return f'<h1>{newposts[id]}</h1>'
else:
#Return a 404 error if the post with the specified id is not found
return '<h1>404</h1><p>Post not found</p>', 404
#return render_template('posts.html', title='Posts', postid = postid )
{% extends "layout.html" %}
{% block content %}
<h1>Posts</h1>
{% if posts is iterable %}
{% for post in posts %}
<article class="media content-section">
<div class="media-body">
<p class="article-content">{{ post.id }}</p>
<h2><a class="article-title" href="posts/1">{{ post.title | safe }}</a></h2>
<p class="article-content">{{ post.content | safe }}</p>
<p class="article-select">{{ post.select | safe }}</p>
<!--<p class="article-select">{{ post.img | safe }}</p>
<img src="{{ post.img }}" alt="image alt text" /> -->
<img src="{{ url_for('static', filename=img) }}">
</div>
</article>
{% endfor %}
{% endif %}
{% endblock content %}
This is the code without the dynamic coding when i use this link in html in html I get type error TypeError: Flask.url_for() takes 2 positional arguments but 3 were given
<h2><a class="article-title" href="{{ url_for('posts','post.id') }}">{{ post.title | safe }}</a></h2>
I tried to use dynamic links but I was given errors