您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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