index.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from flask import Blueprint, render_template
  2. from flask_login import current_user
  3. from configure import conf
  4. import app
  5. from object.blog import BlogArticle
  6. from object.msg import Message
  7. from sql.statistics import get_hello_click, add_hello_click, get_home_click, add_home_click
  8. index = Blueprint("base", __name__)
  9. @index.route('/')
  10. @app.cache.cached(timeout=conf["VIEW_CACHE_EXPIRE"])
  11. def hello_page():
  12. app.HBlogFlask.print_load_page_log(f"hello")
  13. add_hello_click()
  14. return render_template("index/hello.html")
  15. @index.route('/home')
  16. def index_page():
  17. blog_list = BlogArticle.get_blog_list(limit=5, offset=0, not_top=True)
  18. msg_list = Message.get_message_list(limit=6, offset=0, show_secret=False)
  19. app.HBlogFlask.print_load_page_log(f"index")
  20. add_home_click()
  21. return render_template("index/index.html",
  22. blog_list=blog_list,
  23. msg_list=msg_list,
  24. show_email=current_user.check_role("ReadUserInfo"),
  25. hello_clicks=get_hello_click(),
  26. home_clicks=get_home_click())
  27. @index.context_processor
  28. @app.cache.cached(timeout=conf["CACHE_EXPIRE"], key_prefix="inject_base:index")
  29. def inject_base():
  30. """ index默认模板变量, 覆盖app变量 """
  31. return {"top_nav": ["active", "", "", "", "", ""]}
  32. @index.app_context_processor
  33. @app.cache.cached(timeout=conf["CACHE_EXPIRE"], key_prefix="inject_base")
  34. def inject_base():
  35. """ app默认模板变量 """
  36. return {"blog_name": conf['BLOG_NAME'],
  37. "top_nav": ["", "", "", "", "", ""],
  38. "blog_describe": conf['BLOG_DESCRIBE'],
  39. "conf": conf}