From 00f7c1de33f47e70db4ff43c138ba85f07027c3d Mon Sep 17 00:00:00 2001 From: Punnamaraju Vinayaka Tejas Date: Fri, 28 Jul 2023 19:47:32 +0530 Subject: [PATCH] Closes #1 --- flaskr/blog.py | 11 +++++++++++ flaskr/templates/blog/index.html | 7 +++---- flaskr/templates/blog/post.html | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 flaskr/templates/blog/post.html diff --git a/flaskr/blog.py b/flaskr/blog.py index cfa78d8..ec37df5 100644 --- a/flaskr/blog.py +++ b/flaskr/blog.py @@ -66,6 +66,13 @@ def get_post(id, check_author=True): return post +@bp.route('/') +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('//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') diff --git a/flaskr/templates/blog/index.html b/flaskr/templates/blog/index.html index ffd9fbc..d5a9167 100644 --- a/flaskr/templates/blog/index.html +++ b/flaskr/templates/blog/index.html @@ -12,14 +12,13 @@
-

{{ post['title'] }}

+

{{ post['title'] }}

by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}
{% if g.user['id'] == post['author_id'] %} - Edit - {% endif %} + Edit + {% endif %}
-

{{ post['body']|safe }}

{% if not loop.last %}
diff --git a/flaskr/templates/blog/post.html b/flaskr/templates/blog/post.html new file mode 100644 index 0000000..701a37f --- /dev/null +++ b/flaskr/templates/blog/post.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} + +{% block header %} +

{% block title %}{{ post['title']}}{% endblock %}

+{% endblock %} + +{% block content %} +
+
+
+

{{ post['title'] }}

+
by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}
+
+ {% if g.user['id'] == post['author_id'] %} + Edit + {% endif %} +
+

{{ post['body']|safe }}

+
+{% endblock %}