I'm trying to create a web that you can save bookmarks to wall and add some comments to it so you can check it out later. I made a db that keeps the data and now Im trying to display them in my html. Cant seem to fint what is wrong in my code, that its not showing up. Would love some help please. It does add it the the database. Just not show up.
routes:
@app.route('/', methods=['GET', 'POST'])
@app.route('/home', methods=['GET', 'POST'])
def home():
form= AddLinkForm()
bookmarks = Bookmarks.query.order_by(Bookmarks.date_posted.desc())
if form.validate_on_submit():
bookmark = Bookmarks(link=form.link.data, content=form.content.data, author=current_user)
db.session.add(bookmark)
db.session.commit()
flash('Your post has been added!', 'success')
return render_template('home.html', form=form, bookmarks=bookmarks)
models:
class Bookmarks(db.Model):
id = db.Column(db.Integer, primary_key=True)
link = db.Column(db.String, nullable=False)
date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
content = db.Column(db.Text, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
def __repr__(self):
return f"User('{self.link}, {self.content}, {self.date_posted}')"
home.html
{% for bookmark in bookmarks.items %}
<article class="media content-section-bookmark">
<img class="rounded_circle article-img" src="https://assets.stickpng.com/images/67.png" alt="">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="">{{ bookmark.link }}</a>
</div>
<small class="text-muted">{{ bookmark.content }}</small>
<p class="article-content float-right">Read More</p>
<p class="article-content float-right">{{ bookmark.date_posted.strftime('%Y-%m-%d') }}</p>
</div>
</article>
{% endfor %}