Python Flask+Gentelella+Jinja2 快速完成企业内部系统平台快速布局;

1.最近公司运维需求,学习python flask 满足环境治理系统的开发 原生前端Bootstrap 也能满足需求,但是需要前端功基本功(html,css,js)等,折腾了2周发现 实在是太麻烦;

而且布局样式特别low 很难看 各种 按钮和样式效果实现特麻烦(哈哈,原谅我初学者吐槽下,Bootstrap 社区开发人别喷我,谢谢


2.githup 意外发现一个 gentelella 这套后台模板; (非常强大和适用且美观,不用说立马拿下;)


  源码获取地址:https://github.com/puikinsh/gentelella 


3.准备flask 和 python 环境 请移步--  http://blog.51cto.com/breaklinux/2135271



4.使用jinja2布局最快之路;制作base.html ;

     项目结构如下;

image.png


5.base 模板内容结构如下; (

                  1.制作思路:

                     拷贝index 主页的html 代码将,主页中的 head 头部分,CSS样式表,JS 文件,

                   <sidebar menu>  <menu footer buttons>  <!-- top navigation --> <page content> <top tiles --> <footer content> 等部分的代码 

                    单独存放 到 单独的html,项目页面继承 基础base 模板 重写 page content 部分(此部分实际页面内容)


image.png


1.基本模板如下;

 {% block head %}
        {% include 'base/_head.html' %}
     {% endblock %}
    {% block css %}
    {% include 'base/css.html' %}
    {% endblock css %}
: x {% block content %}

            {% endblock content %} {% block sidebar %}
                {% include 'base/sidebar.html' %}
                {% endblock sidebar %}

                {% block footer %}
                {% include 'base/footer.html' %}
                {% endblock footer %}
                {% block sidebarfooter %}
                {% include 'base/sidebar.footer.html' %}
                {% endblock sidebarfooter %}
             {% block navigation %}
            {% include 'base/navigation.html' %}

            {% endblock navigation %}

             {% block content %}

            {% endblock content %}

            {% block js %}
            {% include 'base/js.html' %}
            {% endblock js %}



2.此部分为网页内容实际部分;

 {% block content %}

 {% endblock content %}



3.新增项目静态页面; (include 部分为项目实际内容;本文略;)

{% extends 'base/base.html' %}
{% block content %}
{% include 'index_content.html' %}
{% endblock  content %}



4.配置flask 路由;


sys
time

flask Flaskrequestrender_templateResponse
flask_cors CORS

app = Flask(__name__)
models User

app = Flask(=__name__===)

CORS(app=)

(sys)
sys.setdefaultencoding()


()
():
    index_page = {
        : }
    render_template(=index_page)


5.访问路由 / 查询实际效果:


image.png



6.具体项目内容 可根据需求进行填写; 




猜你喜欢

转载自blog.51cto.com/breaklinux/2152837
今日推荐