记录一下flask常用的命令,每次都找太麻烦啦
前端:
base.html
<!DOCTYPE html> <html lang="ZH-CN"> <head> <meta charset="UTF-8"> <title>{% block title %}{% endblock %}</title> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"> <link rel="stylesheet" href="../static/css/mdui.min.css"> <link rel="stylesheet" href="../static/css/app.css" crossorigin="anonymous"> <script src="../static/js/mdui.min.js"></script> {% block style %}{% endblock %} </head> <body class="mdui-drawer-body-left mdui-appbar-with-toolbar mdui-theme-primary-blue-grey mdui-theme-accent-pink"> <div class="mdui-list" mdui-collapse="{accordion: true}" style="margin-bottom: 76px;"> <div class="mdui-collapse-item {% if request.path=='/home' %} mdui-list-item-active {% endif %}"> <div class="mdui-collapse-item-header mdui-list-item mdui-ripple"> <i class="mdui-list-item-icon mdui-icon material-icons">home</i> <a href="{{ url_for('home')}}" class="mdui-list-item-content mdui-ripple">首页</a> </div> </div> </div> </div> {% block container %}{% endblock %} {% block script %}{% endblock %} </html>
子页面:
{% extends "base.html" %} {% block title %} 首页 {% endblock %} {% block style %} <style type="text/css"> #showSecret { cursor: pointer; color: #607d8b; } </style> {% endblock %} {% block container %} <div class="mdui-container doc-container" style="min-height: 600px;"> </div> {% endblock %}
server.py:
# -*- coding: utf-8 -*- import requests import demjson import operator import logging import const import wj_user import wj_token from flask import Flask from flask import request from flask import render_template from flask import jsonify from recieve import recieve_msg_process from send import send_msg_process app = Flask(__name__) app.logger.setLevel(logging.INFO) @app.route('/admin', methods=['GET']) def hello_world(): return 'hello world, this is JuGuang!!' @app.route('/home', methods=['GET']) def home(): return render_template("home.html") @app.route('/login', methods=['GET']) def login(): if request.method == 'GET': return render_template("login.html") else: pass @app.route('/register', methods=['GET']) def register(): return render_template("register.html") if __name__ == '__main__': app.run(host='0.0.0.0', port=4567, debug=True)
posted on 2019-06-20 21:28 长相思兮长相忆ing 阅读(242) 评论(0) 编辑 收藏 举报