Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

38 lines
1.1KB

  1. # @name: main.py
  2. # @creation_date: 2021-10-20
  3. # @license: The MIT License <https://opensource.org/licenses/MIT>
  4. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  5. # @purpose: Main route for index and other pages
  6. # @acknowledgements:
  7. # https://www.digitalocean.com/community/tutorials/how-to-add-authentication-to-your-app-with-flask-login
  8. from flask import Blueprint, render_template
  9. from flask_login import login_required, current_user
  10. from . import db
  11. from .models import Resource
  12. from sqlalchemy.sql import func
  13. main = Blueprint('main', __name__)
  14. # route for index page
  15. @main.route('/')
  16. def index():
  17. tools = Resource.query.filter_by(type='tool').order_by(func.random()).limit(5).all()
  18. return render_template('index.html', tools=tools)
  19. # route for profile page
  20. @main.route('/profile')
  21. @login_required
  22. def profile():
  23. return render_template('profile.html', name=current_user.name)
  24. # route for test page
  25. @main.route('/test')
  26. def test():
  27. return render_template('test.html')
  28. # route for about page
  29. @main.route('/about')
  30. def about():
  31. return render_template('about.html')