Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. from flask import render_template, request, Blueprint, redirect, url_for
  2. from flask_login import current_user
  3. from website.models import User, Post
  4. from website import db
  5.  
  6. main = Blueprint('main', __name__)
  7.  
  8. @main.route("/")
  9. @main.route("/home")
  10. def home():
  11. page = request.args.get('page', 1, type=int)
  12. posts = Post.query.filter_by(author=current_user)
  13. posts = posts + current_user.followed_posts()
  14. posts = posts.paginate(page=page, per_page=5)
  15. return render_template('home.html', posts=posts)
  16.  
  17. @main.route("/explore")
  18. def expore():
  19. page = request.args.get('page', 1, type=int)
  20. posts =
  21. Post.query.order_by(Post.date_posted.desc()).paginate(page=page,
  22. per_page=5)
  23. return render_template('home.html', posts=posts)
  24.  
  25. @main.route("/about")
  26. def about():
  27. return render_template('about.html', title='About')
  28.  
  29. {% extends "layout.html" %}
  30. {% block content %}
  31. {% for post in posts.items %}
  32. <article class="media content-section">
  33. <img class="rounded-circle article-img" src="{{ url_for('static',
  34. filename='profile_pics/' + post.author.image_file) }}">
  35. <div class="media-body">
  36. <div class="article-metadata">
  37. <a class="mr-2" href="{{ url_for('users.user_posts',
  38. username=post.author.username) }}">{{ post.author.username }}</a>
  39. <small class="text-muted">{{ post.date_posted.strftime('%d-%m-%Y')
  40. }}</small>
  41. </div>
  42. <h2><a class="article-title" href="{{ url_for('posts.post',
  43. post_id=post.id|string) }}">{{ post.title }}</a></h2>
  44. <p class="article-content">{{ post.content }}</p>
  45. </div>
  46. </article>
  47. {% endfor %}
  48. {% for page_num in posts.iter_pages(left_edge=1, right_edge=1,
  49. left_current=1, right_current=2) %}
  50. {% if page_num %}
  51. {% if posts.page ==page_num %}
  52. <a class="btn btn-dark mb-4"href="{{ url_for('main.home',
  53. page=page_num) }}">{{ page_num }}</a>
  54. {% else %}
  55. <a class="btn btn-outline-dark mb-4"href="{{ url_for('main.home',
  56. page=page_num) }}">{{ page_num }}</a>
  57. {% endif %}
  58. {% else %}
  59. ...
  60. {% endif %}
  61. {% endfor %}
  62. {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement