import html from flask import render_template, request, flash, redirect, url_for from webapp.routes import * from oshipka.webapp import app from webapp.models import BlogPost from flaskext.markdown import Markdown Markdown(app, extensions=['markdown.extensions.fenced_code', 'markdown.extensions.codehilite', 'markdown.extensions.sane_lists', 'markdown.extensions.tables'], safe_mode='escape') @app.template_filter('rawhtmlparse') def rawhtmlparse(text): splitted = text.split("{% rawhtml %}") final_text = splitted[0] for idx, entry in enumerate(splitted[1:]): splitted_entry = entry.split("{% endrawhtml %}") unescaped_entry = html.unescape(splitted_entry[0]) final_text = "{}{}{}".format(final_text, unescaped_entry, splitted_entry[1]) return final_text @app.route('/') def home(): per_page = request.args.get('per_page', 5) blog_post_pagination = BlogPost.query.order_by(BlogPost.created_dt.desc()).paginate(per_page=per_page, error_out=False) return render_template("home.html", blog_post_pagination=blog_post_pagination) @app.route('/index') def index(): blog_posts = BlogPost.query.order_by(BlogPost.created_dt.desc()).all() return render_template("index.html", blog_posts=blog_posts) @app.route('/aboutme') def aboutme(): return render_template("aboutme.html") @app.route('/blog_post/') def blog_post_filename(filename): blog_post = BlogPost.query.filter_by(filename=filename).first() if not blog_post: flash("Blog post doesn't exist") return redirect(url_for('index')) return render_template("blog_post/get.html", instance=blog_post)