1
0
Эх сурвалжийг харах

feat: 实现主页基本架构

SongZihuan 2 жил өмнө
parent
commit
dc88689ea7

+ 11 - 0
app/__init__.py

@@ -23,12 +23,22 @@ class HTalkFlask(Flask):
         self.update_configure()
         self.profile_setting()
         self.logging_setting()
+        self.blueprint()
 
         db.init_app(self)
         moment.init_app(self)
         mail.init_app(self)
         migrate.init_app(self, db)
 
+        @self.context_processor
+        def inject_base():
+            """ app默认模板变量 """
+            return {"conf": conf}
+
+    def blueprint(self):
+        from .index import index
+        self.register_blueprint(index, url_prefix="/")
+
     def profile_setting(self):
         if conf["DEBUG_PROFILE"]:
             self.wsgi_app = ProfilerMiddleware(self.wsgi_app, sort_by=("cumtime",))
@@ -52,3 +62,4 @@ class HTalkFlask(Flask):
     def update_configure(self):
         """ 更新配置 """
         self.config.update(conf)
+

+ 9 - 0
app/index.py

@@ -0,0 +1,9 @@
+from flask import Blueprint, render_template, request
+
+
+index = Blueprint("base", __name__)
+
+
+@index.route("/")
+def index_page():
+    return render_template("index/index.html")

+ 3 - 0
configure/__init__.py

@@ -17,6 +17,9 @@ conf: Dict[str, any] = {
     "SECRET_KEY": "11111111",
     "SQLALCHEMY_DATABASE_URI": "mysql+pymysql://root:12345678@localhost:3306/htalk",
     "SQLALCHEMY_TRACK_MODIFICATIONS": False,
+    "LOGO": "icon.svg",
+    "WEBSITE_NAME": "HTalk",
+    "WEBSITE_TITLE": "HTalk-优秀的用户交流网站"
 }
 
 

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
static/icon.svg


+ 80 - 0
templates/base.html

@@ -0,0 +1,80 @@
+{% import "macro.html" as macro %}
+
+<!DOCTYPE html>
+<html lang="zh">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+
+    {% block icon %}
+        <link rel="icon" href="{{ url_for('static', filename=conf["LOGO"]) }}" type="image/x-icon"/>
+    {% endblock %}
+
+    {% block font %}
+        <link rel="preconnect" href="https://fonts.googleapis.com">
+        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+        <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@100;400&display=swap" rel="stylesheet">
+    {% endblock %}
+
+    {% block style %}
+        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
+        <style>
+            html {
+                font-family: 'Noto Sans SC', sans-serif;
+            }
+        </style>
+    {% endblock %}
+
+    {% block javascript %}
+        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
+        {{ moment.include_moment() }}
+        {{ moment.lang("zh-CN") }}
+    {% endblock %}
+
+    <title>{% block title %} {% endblock %} - {{ conf["WEBSITE_NAME"] }} </title>
+</head>
+
+<body>
+    {% block nav %}
+        <div class="container mt-2">
+            <a class="h3" href="/" style="text-decoration:none;color:#333;"> {{ conf["WEBSITE_TITLE"] }} </a>
+            <a class="btn btn-success float-end text-white"> 用户信息 </a>
+        </div>
+    {% endblock %}
+
+    <div class="container mt-2">
+        <ul class="nav nav-tabs justify-content-center">
+            <li class="nav-item">
+                <a class="nav-link active" data-bs-toggle="tab" href="#home"> 主页 </a>
+            </li>
+            <li class="nav-item">
+                 <a class="nav-link" data-bs-toggle="tab" href="#look"> 关注 </a>
+            </li>
+            <li class="nav-item">
+                <a class="nav-link" data-bs-toggle="tab" href="#archive"> 归档 </a>
+            </li>
+            <li class="nav-item">
+                <a class="nav-link" data-bs-toggle="tab" href="#follow"> 关注的人 </a>
+            </li>
+            {% block nav_ %} {% endblock %}
+        </ul>
+
+        <!-- Tab panes -->
+        <div class="tab-content">
+            <div class="tab-pane container fade active show" id="home">
+                主页
+            </div>
+            <div class="tab-pane fade container" id="look">
+                关注
+            </div>
+            <div class="tab-pane fade container" id="archive">
+                归档
+            </div>
+            <div class="tab-pane fade container" id="follow">
+                关注的人
+            </div>
+            {% block content_ %} {% endblock %}
+        </div>
+    </div>
+</body>
+</html>

+ 3 - 0
templates/index/index.html

@@ -0,0 +1,3 @@
+{% extends "base.html" %}
+
+{% block title %} 主页 {% endblock %}

+ 0 - 0
templates/macro.html


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно