Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import render_template, request, Blueprint, redirect, url_for
- from flask_login import current_user
- from website.models import User, Post
- from website import db
- main = Blueprint('main', __name__)
- @main.route("/")
- @main.route("/home")
- def home():
- page = request.args.get('page', 1, type=int)
- posts = Post.query.filter_by(author=current_user)
- posts = posts + current_user.followed_posts()
- posts = posts.paginate(page=page, per_page=5)
- return render_template('home.html', posts=posts)
- @main.route("/explore")
- def expore():
- page = request.args.get('page', 1, type=int)
- posts =
- Post.query.order_by(Post.date_posted.desc()).paginate(page=page,
- per_page=5)
- return render_template('home.html', posts=posts)
- @main.route("/about")
- def about():
- return render_template('about.html', title='About')
- {% extends "layout.html" %}
- {% block content %}
- {% for post in posts.items %}
- <article class="media content-section">
- <img class="rounded-circle article-img" src="{{ url_for('static',
- filename='profile_pics/' + post.author.image_file) }}">
- <div class="media-body">
- <div class="article-metadata">
- <a class="mr-2" href="{{ url_for('users.user_posts',
- username=post.author.username) }}">{{ post.author.username }}</a>
- <small class="text-muted">{{ post.date_posted.strftime('%d-%m-%Y')
- }}</small>
- </div>
- <h2><a class="article-title" href="{{ url_for('posts.post',
- post_id=post.id|string) }}">{{ post.title }}</a></h2>
- <p class="article-content">{{ post.content }}</p>
- </div>
- </article>
- {% endfor %}
- {% for page_num in posts.iter_pages(left_edge=1, right_edge=1,
- left_current=1, right_current=2) %}
- {% if page_num %}
- {% if posts.page ==page_num %}
- <a class="btn btn-dark mb-4"href="{{ url_for('main.home',
- page=page_num) }}">{{ page_num }}</a>
- {% else %}
- <a class="btn btn-outline-dark mb-4"href="{{ url_for('main.home',
- page=page_num) }}">{{ page_num }}</a>
- {% endif %}
- {% else %}
- ...
- {% endif %}
- {% endfor %}
- {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement