This commit is contained in:
Punnamaraju Vinayaka Tejas 2023-07-28 19:47:32 +05:30
parent 57df913a2c
commit 00f7c1de33
3 changed files with 34 additions and 4 deletions

View file

@ -66,6 +66,13 @@ def get_post(id, check_author=True):
return post
@bp.route('/<int:id>')
def post(id):
post = get_post(id, check_author=False)
post = dict(post)
post['body'] = markdown.markdown(post['body'])
return render_template('blog/post.html', post=post)
@bp.route('/<int:id>/update', methods=('GET', 'POST'))
@login_required
def update(id):
@ -101,3 +108,7 @@ def delete(id):
db.execute('DELETE FROM post WHERE id = ?',(id,))
db.commit()
return redirect(url_for('blog.index'))
@bp.route('/temp')
def temp():
return render_template('temp.html')

View file

@ -12,14 +12,13 @@
<article class="post">
<header>
<div>
<h1>{{ post['title'] }}</h1>
<h1><a href="{{ url_for('blog.post', id=post['id']) }}">{{ post['title'] }}</a></h1>
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
</div>
{% if g.user['id'] == post['author_id'] %}
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
{% endif %}
<a href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
{% endif %}
</header>
<p class="body">{{ post['body']|safe }}</p>
</article>
{% if not loop.last %}
<hr>

View file

@ -0,0 +1,20 @@
{% extends 'base.html' %}
{% block header %}
<h1>{% block title %}{{ post['title']}}{% endblock %}</h1>
{% endblock %}
{% block content %}
<article class="post">
<header>
<div>
<h1>{{ post['title'] }}</h1>
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
</div>
{% if g.user['id'] == post['author_id'] %}
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
{% endif %}
</header>
<p class="body">{{ post['body']|safe }}</p>
</article>
{% endblock %}