资讯专栏INFORMATION COLUMN

Flask四之模板

sarva / 3016人阅读

摘要:控制结构条件控制语句循环还支持宏。宏类似于代码中的函数。在指令之后,基模板中的个块被重新定义,模板引擎会将其插入适当的位置。初始化之后,就可以在程序中使用一个包含所有文件的基模板。之前版本的模板中的欢迎信息,现在就放在这个页面头部。

四、模板
FMTV
F:form表单
M:Model模型(数据库)
T:Template模板
V:view视图(路由)
1、渲染模板
模板是一个包含响应文本的文件,其中包含用占位变量表示的动态部分,其具体值
只在请求的上下文中才能知道。 使用真实值替换变量,再返回最终得到的响应字符
串,这一过程称为渲染。可以使用 render_template() 方法来渲染模板。你需要做
的一切就是将模板名和你想作为关键字的参数传入模板的变量。
Flask 会在 templates 文件夹里寻找模板。所以,如果你的应用是个模块,这个文
件夹应该与模块同级;如果它是一个包,那么这个文件夹作为包的子目录:
模板:
/application.py
/templates
    /hello.html

包:

/application
    /__init__.py
    /templates
        /hello.html

【hello.html】

Hello World!

from flask import render_template @app.route("/hellotemplate/") def hellotemplate(): return render_template("hello.html")

模板引擎
Flask使用了一个名为 Jinja2 的强大模板引擎

{% ... %} Jinja语句,例如判断、循环语句

{{ ... }} 变量,会显示在浏览器中

{# ... #} 注释,不会输出到浏览器中

2、变量规则

在模板中使用的 {{ name }} 结构表示一个变量,它是一种特殊的占位符,告诉
模板引擎这个位置的值从渲染模板时使用的数据中获取。
【helloname.html】

Hello, {{ name }}!

@app.route("/hellotemplate/") def helloname(name): return render_template("helloname.html",name = name)

可以使用过滤器修改变量,过滤器名添加在变量名之后,中间使用竖线分隔。

3、控制结构

1、条件控制语句
【if.html】

{% if name %}
hello, {{name}}
{% else %}
hello, world!
{% endif %}

2、 for 循环
【for.html】

    {% for a in range(10) %}
  1. a
  2. {% endfor %}
@app.route("/for/") def fortemplate(): return render_template("for.html")

3、Jinja2 还支持宏(macro) 。宏类似于 Python 代码中的函数(def)。
【macro.html】

{% macro myprint(A) %}
this is {{ A }}
{% endmacro %}

{{ myprint(A) }}


@app.route("/macro/")
def macrotamplate(a):
    return render_template("macro.html",A = a)

为了重复使用宏,我们可以将其保存在多带带的文件中,然后在需要使用的模板中导入:
【macro2.html】

{% from "macro.html" import myprint %}
{{ myprint(A) }}

@app.route("/macro2/")
def macro2template(a):
    return render_template("macro2.html",A = a)

4、包含(include)
【include.html】

{% include "macro.html" %}


@app.route("/include/")
def includetemplate(a):
    return render_template("include.html",A = a)

【注意】
包含进来的文件里的所有变量也包含进来了,需要在视图函数中指定

4、模板继承

首先,创建一个名为 base.html 的基模板:
【base.html】



    {% block head %}
    
        {% block title %}
        {% endblock %}
        - My Application
    
    {% endblock %}



{% block body %}
{% endblock %}


block 标签定义的元素可在衍生模板中修改。下面这个示例是基模板的衍生模板:
【extend.html】

% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
{{ super() }}

super

{% endblock %} {% block body %}

Hello, World!

{% endblock %}
extends 指令声明这个模板衍生自 base.html。在 extends 指令之后,基模板中的
3个块被重新定义,模板引擎会将其插入适当的位置。如果想添加内容到在父模板
内已经定义的块,又不想失去父模板里的内容,可以使用super函数
5、使用Flask-Bootstrap

Flask-Bootstrap 使用 pip安装:

(venv) $ pip install flask-bootstrap

Flask 扩展一般都在创建程序实例后就初始化。
初始化 Flask-Bootstrap 之后,就可以在程序中使用一个包含所有 Bootstrap 文件
的基模板。
【boootstrap.html】

{% extends "bootstrap/base.html" %}

{% block title %}Flasky{% endblock %}

{% block navbar %}

{% endblock %}

{% block content %}
{% endblock %}
Jinja2 中的 extends 指令从 Flask-Bootstrap 中导入 bootstrap/base.html,从而
实现模板继承。

Flask-Bootstrap 中的基模板提供了一个网页框架,引入了 Bootstrap 中的所有 CSS 
和JavaScript 文件。基模板中定义了可在衍生模板中重定义的块。 block 和 endblock 
指令定义的块中的内容可添加到基模板中。
上面这个 boootstrap.html 模板定义了 3 个块,分别名为 title、 navbar 和 content。
这些块都是基模板提供的, 可在衍生模板中重新定义。 title 块的作用很明显,其中
的内容会出现在渲染后的 HTML 文档头部,放在  标签中。 navbar 和 content 
这两个块分别表示页面中的导航条和主体内容。在这个模板中, navbar 块使用 Bootstrap 
组件定义了一个简单的导航条。content 块中有个<div> 容器,其中包含一个页面头部。
之前版本的模板中的欢迎信息,现在就放在这个页面头部。</pre>
<pre>from flask_bootstrap import Bootstrap
bootstrap = Bootstrap(app)
@app.route("/bootstrap/<name>")
def bootstraptemplate(name):
    return render_template("boootstrap.html",name = name)</pre>
<p><strong> 【注意】 </strong> <br>很多块都是 Flask-Bootstrap 自用的,如果直接重定义可能会导致一些问题。例如, <br>Bootstrap 所需的文件在 styles 和 scripts 块中声明。如果程序需要向已经有内<br>容的块中添加新内容,必须使用Jinja2 提供的 super() 函数。例如,如果要在衍生<br>模板中添加新的 JavaScript 文件,需要这么定义 scripts 块:</p>
<pre>{% block scripts %}
{{ super() }}
<script type="text/javascript" src="my-script.js"></script>
{% endblock %}</pre>
<b>6、自定义错误页面</b>
<p>【templates/404.html】</p>
<pre><h1> Page is not Found </h1>
@app.errorhandler(404)
def page_not_found(e):
    return render_template("404.html"), 404</pre>
<p>【templates/base.html: 包含导航条的程序基模板】</p>
<pre>{% extends "bootstrap/base.html" %}

{% block title %}Flasky{% endblock %}

{% block head %}
{{ super() }}
<link rel="shortcut icon" href="{{ url_for("static", filename="favicon.ico") }}" type="image/x -icon">
<link rel="icon" href="{{ url_for("static", filename="favicon.ico") }}" type="image/x -icon">
{% endblock %}

{% block navbar %}
<div class="navbar navbar-inverse" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Flasky</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="/">Home</a></li>
            </ul>
        </div>
    </div>
</div>
{% endblock %}

{% block content %}
<div class="container">
{% block page_content %}{% endblock %}
</div>
{% endblock %}

{% block scripts %}
{{ super() }}
{{ moment.include_moment() }}
{% endblock %}</pre>
<p>这个模板的 content 块中只有一个 <div> 容器,其中包含了一个名为 <br>page_content 的新的空块,块中的内容由衍生模板定义。</p>
<p>【templates/404.html:使用模板继承机制自定义 404 错误页面】</p>
<pre>{% extends "base.html" %}
{% block title %}Flasky - Page Not Found{% endblock %}
{% block page_content %}
<div class="page-header">
<h1>Not Found</h1>
</div>
{% endblock %}</pre>
<p>templates/boootstrap.html 现在可以通过继承这个基模板来简化内容:<br>【 templates/boootstrap.html: 使用模板继承机制简化页面模板】</p>
<pre>{% extends "base.html" %}
{% block title %}Flasky{% endblock %}
{% block page_content %}
<div class="page-header">
<h1>Hello, {{ name }}!</h1>
</div>
{% endblock %}</pre>
<b>7、静态文件</b>
<p>默认设置下, Flask 在程序根目录中名为 static 的子目录中寻找静态文件。<br>如果需要,可在static 文件夹中使用子文件夹存放文件。给静态文件生成 <br>URL ,使用特殊的 "static" 端点名:<br>【westeros.html】</p>
<pre><img src = "{{url_for("static",filename = "westeros.jpg")}}">
@app.route("/westeros/")
def westeros():
    return render_template("westeros.html")</pre>
<p>这个文件应该存储在文件系统上的 static/westeros.jpg 。</p>
<b>8、使用Flask-Moment本地化日期和时间</b>
<p>lask-Moment 是一个 Flask 程序扩展,能把moment.js 集成到 Jinja2 模<br>板中。 Flask-Moment 可以使用 pip 安装:</p>
<pre>(venv) $ pip install flask-moment</pre>
<p>这个扩展的初始化方法和Bootstrap一样,以程序实例app为参数:</p>
<pre>from flask_moment import Moment
moment = Moment(app)</pre>
<p>除了 moment.js, Flask-Moment 还依赖 jquery.js。要在 HTML 文档的某个<br>地方引入这两个库,可以直接引入,这样可以选择使用哪个版本,也可使用扩<br>展提供的辅助函数,从内容分发网络(Content Delivery Network, CDN)中<br>引入通过测试的版本。 Bootstrap 已经引入了 jquery.js, 因此只需引入 <br>moment.js即可。<br>【base.html中增加了】</p>
<pre>{% block scripts %}
{{ super() }}
{{ moment.include_moment() }}
{% endblock %}</pre>
<p>【moment.html】</p>
<pre>{% extends "base.html" %}
{% block page_content %}
<div class="page-header">
<h1>Hello World!</h1>
</div>
<p>The local date and time is {{moment(current_time).format("LLL")}}.</p>
<p>That was {{moment(current_time).fromNow(refresh = true)}}.</p>
{% endblock %}</pre>
<p>把变量current_time 传入模板进行渲染</p>
<pre>from datetime import datetime
@app.route("/moment/")
def momenttemplate():
return render_template("moment.html",current_time = datetime.utcnow())</pre>           
               
                                           
                       
                 </div>
            
                     <div class="mt-64 tags-seach" >
                 <div class="tags-info">
                                                                                                                    
                         <a style="width:120px;" title="混合云" href="https://www.ucloud.cn/site/product/uhybrid.html">混合云</a>
                                             
                         <a style="width:120px;" title="私有云" href="https://www.ucloud.cn/site/product/ucloudstack.html">私有云</a>
                                                                                                                                                 
                                      
                     
                    
                                                                                               <a style="width:120px;" title="Flask" href="https://www.ucloud.cn/yun/tag/Flask/">Flask</a>
                                                                                                           <a style="width:120px;" title="flask建站" href="https://www.ucloud.cn/yun/tag/flaskjianzhan/">flask建站</a>
                                                                                                           <a style="width:120px;" title="flask 接收表单数据" href="https://www.ucloud.cn/yun/tag/flask jieshoubiaodanshuju/">flask 接收表单数据</a>
                                                                                                           <a style="width:120px;" title="flask 部署 腾讯云" href="https://www.ucloud.cn/yun/tag/flask bushu tengxunyun/">flask 部署 腾讯云</a>
                                                         
                 </div>
               
              </div>
             
               <div class="entry-copyright mb-30">
                   <p class="mb-15"> 文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。</p>
                 
                   <p>转载请注明本文地址:https://www.ucloud.cn/yun/40796.html</p>
               </div>
                      
               <ul class="pre-next-page">
                 
                                  <li class="ellipsis"><a class="hpf" href="https://www.ucloud.cn/yun/40795.html">上一篇:Flask五之表单</a></li>  
                                                
                                       <li class="ellipsis"><a class="hpf" href="https://www.ucloud.cn/yun/40797.html">下一篇:Flask三之请求与响应</a></li>
                                  </ul>
              </div>
              <div class="about_topicone-mid">
                <h3 class="top-com-title mb-0"><span data-id="0">相关文章</span></h3>
                <ul class="com_white-left-mid atricle-list-box">
                             
                                                                    <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/110778.html"><b><em>Flask</em><em>四之</em><em>模板</em></b></a></h2>
                                                     <p class="ellipsis2 good">摘要:控制结构条件控制语句循环还支持宏。宏类似于代码中的函数。在指令之后,基模板中的个块被重新定义,模板引擎会将其插入适当的位置。初始化之后,就可以在程序中使用一个包含所有文件的基模板。之前版本的模板中的欢迎信息,现在就放在这个页面头部。

四、模板
FMTV
F:form表单
M:Model模型(数据库)
T:Template模板
V:view视图(路由)

1、渲染模板
模板是一个包含响应...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-449.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/04/small_000000449.jpg" alt=""><span class="layui-hide64">HackerShell</span></a>
                                    <time datetime="">2019-08-28 17:46</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/45842.html"><b><em>Flask</em><em>四之</em><em>模板</em></b></a></h2>
                                                     <p class="ellipsis2 good">摘要:控制结构条件控制语句循环还支持宏。宏类似于代码中的函数。在指令之后,基模板中的个块被重新定义,模板引擎会将其插入适当的位置。初始化之后,就可以在程序中使用一个包含所有文件的基模板。之前版本的模板中的欢迎信息,现在就放在这个页面头部。

四、模板
FMTV
F:form表单
M:Model模型(数据库)
T:Template模板
V:view视图(路由)

1、渲染模板
模板是一个包含响应...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-1349.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/13/small_000001349.jpg" alt=""><span class="layui-hide64">Dionysus_go</span></a>
                                    <time datetime="">2019-07-31 14:37</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/10294.html"><b><em>Flask</em><em>四之</em><em>模板</em></b></a></h2>
                                                     <p class="ellipsis2 good">摘要:控制结构条件控制语句循环还支持宏。宏类似于代码中的函数。在指令之后,基模板中的个块被重新定义,模板引擎会将其插入适当的位置。初始化之后,就可以在程序中使用一个包含所有文件的基模板。之前版本的模板中的欢迎信息,现在就放在这个页面头部。

四、模板
FMTV
F:form表单
M:Model模型(数据库)
T:Template模板
V:view视图(路由)

1、渲染模板
模板是一个包含响应...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-489.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/04/small_000000489.jpg" alt=""><span class="layui-hide64">shuibo</span></a>
                                    <time datetime="">2019-06-21 14:29</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/36272.html"><b>openresty 前端开发入门<em>四之</em>Redis篇</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:这章主要演示怎么通过连接,并根据用户输入的从获取,并返回给用户操作主要用到了库,代码可以在上找得到而且上面也有实例代码由于官网给出的例子比较基本,代码也比较多,所以我这里主要介绍一些怎么封装一下,简化我们调用的代码密码,没有密码

这章主要演示怎么通过lua连接redis,并根据用户输入的key从redis获取value,并返回给用户
操作redis主要用到了lua-resty-redi...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-430.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/04/small_000000430.jpg" alt=""><span class="layui-hide64">2shou</span></a>
                                    <time datetime="">2019-07-24 14:47</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/46260.html"><b>Tshare校园资源分享平台(网站开发<em>四之</em>功能模块设计)</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:文件搜索通过关键字搜索文件,搜索时采用模糊搜索,可以对整个关键字进行模糊搜索,还可以将关键字进行中文分词后再依次模糊搜索。所以需要提供中文分词的功能。

上一篇博客地址:Tshare校园资源分享平台(网站开发三之数据库连接)
功能设计
虽然我们能访问web站点,能连接数据库了,但是并不意味着我们马上就要开始写代码,我们得先分析一下我们的网站都需要实现哪些功能,这样我们才能针对如何实现这些...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-731.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/07/small_000000731.jpg" alt=""><span class="layui-hide64">yedf</span></a>
                                    <time datetime="">2019-07-31 15:15</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                           
                </ul>
              </div>
              
               <div class="topicone-box-wangeditor">
                  
                  <h3 class="top-com-title mb-64"><span>发表评论</span></h3>
                   <div class="xcp-publish-main flex_box_zd">
                                      
                      <div class="unlogin-pinglun-box">
                        <a href="javascript:login()" class="grad">登陆后可评论</a>
                      </div>                   </div>
               </div>
              <div class="site-box-content">
                <div class="site-content-title">
                  <h3 class="top-com-title mb-64"><span>0条评论</span></h3>   
                </div> 
                      <div class="pages"></ul></div>
              </div>
           </div>
           <div class="layui-col-md4 layui-col-lg3 com_white-right site-wrap-right">
              <div class=""> 
                <div class="com_layuiright-box user-msgbox">
                    <a href="https://www.ucloud.cn/yun/u-106.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/01/small_000000106.jpg" alt=""></a>
                    <h3><a href="https://www.ucloud.cn/yun/u-106.html" rel="nofollow">sarva</a></h3>
                    <h6>男<span>|</span>高级讲师</h6>
                    <div class="flex_box_zd user-msgbox-atten">
                     
                                                                      <a href="javascript:attentto_user(106)" id="attenttouser_106" class="grad follow-btn notfollow attention">我要关注</a>
      
                                                                                        <a href="javascript:login()" title="发私信" >我要私信</a>
                     
                                            
                    </div>
                    <div class="user-msgbox-list flex_box_zd">
                          <h3 class="hpf">TA的文章</h3>
                          <a href="https://www.ucloud.cn/yun/ut-106.html" class="box_hxjz">阅读更多</a>
                    </div>
                      <ul class="user-msgbox-ul">
                                                  <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/130908.html">用conda安装tensorflow</a></h3>
                            <p>阅读 732<span>·</span>2023-04-26 01:47</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/124476.html">OpenCV 自定义线性滤波</a></h3>
                            <p>阅读 2091<span>·</span>2021-11-23 09:51</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/123867.html">新网:双11上云嘉年华,.com域名低至16元/首年;.cn域名低至8.8元/首年</a></h3>
                            <p>阅读 1412<span>·</span>2021-11-18 13:19</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/121500.html">LeetCode 1022. 从根到叶的二进制数之和</a></h3>
                            <p>阅读 518<span>·</span>2021-09-29 09:34</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/116353.html">css如何实现n宫格布局?</a></h3>
                            <p>阅读 1853<span>·</span>2019-08-30 15:44</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/116179.html">前端动画专题(三):撩人的按钮特效</a></h3>
                            <p>阅读 482<span>·</span>2019-08-30 15:44</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/116111.html">CSS那些事儿</a></h3>
                            <p>阅读 2149<span>·</span>2019-08-30 15:44</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/115770.html">侧边栏的固定与自适应原来是这样实现的(持续更新)</a></h3>
                            <p>阅读 1090<span>·</span>2019-08-30 14:06</p></li>
                                                
                      </ul>
                </div>
                <!-- 云社区相关服务 -->
                 
<div class="com_layuiright-box">
                  <h3 class="top-com-title"><span>云社区相关服务</span></h3> 
                    <div class="community-box flex_box flex_wrap community-box1">
                        <a href="https://www.ucloud.cn/yun/question/add.html" rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/static/theme/ukd/images/topicone-icon1.png" alt="提问">
                            <span>提问</span>
                        </a>
                        <a href="https://www.ucloud.cn/yun/article"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/static/theme/ukd/images/topicone-icon2.png" alt="学习">
                            <span>学习</span>
                        </a>
                        
                        <a href="https://www.ucloud.cn/yun/user/vertify.html" rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/static/theme/ukd/images/topicone-icon4.png" alt="认证">
                            <span>认证</span>
                        </a>
                      
                        <a href="https://www.ucloud.cn/site/product/uhost.html?ytag=seo" rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/static/theme/ukd/images/topicone-icon5.png" alt="产品">
                            <span>产品</span>
                        </a>
                        
                        <a href="https://spt.ucloud.cn/30001?ytag=seo" rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/static/theme/ukd/images/topicone-icon6.png" alt="技术服务">
                            <span>技术服务</span>
                        </a>
                          <a href="https://spt.ucloud.cn/30001?ytag=seo" rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/static/theme/ukd/images/topicone-icon3.png" alt="售前咨询">
                            <span>售前咨询</span>
                        </a>
                    </div>   
                </div>                   <!-- 文章详情右侧广告-->
              
  <div class="com_layuiright-box">
                  <h6 class="top-com-title"><span>最新活动</span></h6> 
           
         <div class="com_adbox">
                    <div class="layui-carousel" id="right-item">
                      <div carousel-item>
                                                                                                                       <div>
                          <a href="https://www.ucloud.cn/site/product/uhost.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220620/Z7TLrpAi.png" alt="云服务器">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/uhybrid.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220620/MWraMsBh.png" alt="混合云">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/ucloudstack.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220620/ifzOxvjW.png" alt="私有云">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/utrion.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220620/VDqwC1iN.png" alt="超融合服务器">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/uhybrid.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220630/pJwnviKN.png" alt="服务器托管">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/uxzone.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/220630/CDb5uXxp.jpeg" alt="idc机房托管">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/active/network.html?ytag=seo"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/230227/XWsSXmvm.png" alt="专线服务">                                 
                          </a>
                        </div>
                                                                   
                    
                        
                      </div>
                    </div>
                      
                    </div>                    <!-- banner结束 -->
              
<div class="adhtml">

</div>
                <script>
                $(function(){
                    $.ajax({
                        type: "GET",
                                url:"https://www.ucloud.cn/yun/ad/getad/1.html",
                                cache: false,
                                success: function(text){
                                  $(".adhtml").html(text);
                                }
                        });
                    })
                </script>                </div>              </div>
           </div>
        </div>
      </div> 
    </section>
    <!-- wap拉出按钮 -->
     <div class="site-tree-mobile layui-hide">
      <i class="layui-icon layui-icon-spread-left"></i>
    </div>
    <!-- wap遮罩层 -->
    <div class="site-mobile-shade"></div>
    
       <!--付费阅读 -->
       <div id="payread">
         <div class="layui-form-item">阅读需要支付1元查看</div>  
         <div class="layui-form-item"><button class="btn-right">支付并查看</button></div>     
       </div>
      <script>
      var prei=0;

       
       $(".site-seo-depict pre").each(function(){
          var html=$(this).html().replace("<code>","").replace("</code>","").replace('<code class="javascript hljs" codemark="1">','');
          $(this).attr('data-clipboard-text',html).attr("id","pre"+prei);
          $(this).html("").append("<code>"+html+"</code>");
         prei++;
       })
           $(".site-seo-depict img").each(function(){
             
            if($(this).attr("src").indexOf('data:image/svg+xml')!= -1){
                $(this).remove();
            }
       })
     $("LINK[href*='style-49037e4d27.css']").remove();
       $("LINK[href*='markdown_views-d7a94ec6ab.css']").remove();
layui.use(['jquery', 'layer','code'], function(){
  $("pre").attr("class","layui-code");
      $("pre").attr("lay-title","");
       $("pre").attr("lay-skin","");
  layui.code(); 
       $(".layui-code-h3 a").attr("class","copycode").html("复制代码 ").attr("onclick","copycode(this)");
      
});
function copycode(target){
    var id=$(target).parent().parent().attr("id");
  
                  var clipboard = new ClipboardJS("#"+id);

clipboard.on('success', function(e) {


    e.clearSelection();
    alert("复制成功")
});

clipboard.on('error', function(e) {
    alert("复制失败")
});
}
//$(".site-seo-depict").html($(".site-seo-depict").html().slice(0, -5));
</script>
  <link rel="stylesheet" type="text/css" href="https://www.ucloud.cn/yun/static/js/neweditor/code/styles/tomorrow-night-eighties.css">
    <script src="https://www.ucloud.cn/yun/static/js/neweditor/code/highlight.pack.js" type="text/javascript"></script>
    <script src="https://www.ucloud.cn/yun/static/js/clipboard.js"></script>

<script>hljs.initHighlightingOnLoad();</script>

<script>
    function setcode(){
        var _html='';
    	  document.querySelectorAll('pre code').forEach((block) => {
        	  var _tmptext=$.trim($(block).text());
        	  if(_tmptext!=''){
        		  _html=_html+_tmptext;
        		  console.log(_html);
        	  }
    		 
    		  
    		 
      	  });
    	 

    }

</script>

<script>
function payread(){
  layer.open({
      type: 1,
      title:"付费阅读",
      shadeClose: true,
      content: $('#payread')
    });
}
// 举报
function jupao_tip(){
  layer.open({
      type: 1,
      title:false,
      shadeClose: true,
      content: $('#jubao')
    });

}
$(".getcommentlist").click(function(){
var _id=$(this).attr("dataid");
var _tid=$(this).attr("datatid");
$("#articlecommentlist"+_id).toggleClass("hide");
var flag=$("#articlecommentlist"+_id).attr("dataflag");
if(flag==1){
flag=0;
}else{
flag=1;
//加载评论
loadarticlecommentlist(_id,_tid);
}
$("#articlecommentlist"+_id).attr("dataflag",flag);

})
$(".add-comment-btn").click(function(){
var _id=$(this).attr("dataid");
$(".formcomment"+_id).toggleClass("hide");
})
$(".btn-sendartcomment").click(function(){
var _aid=$(this).attr("dataid");
var _tid=$(this).attr("datatid");
var _content=$.trim($(".commenttext"+_aid).val());
if(_content==''){
alert("评论内容不能为空");
return false;
}
var touid=$("#btnsendcomment"+_aid).attr("touid");
if(touid==null){
touid=0;
}
addarticlecomment(_tid,_aid,_content,touid);
})
 $(".button_agree").click(function(){
 var supportobj = $(this);
         var tid = $(this).attr("id");
         $.ajax({
         type: "GET",
                 url:"https://www.ucloud.cn/yun/index.php?topic/ajaxhassupport/" + tid,
                 cache: false,
                 success: function(hassupport){
                 if (hassupport != '1'){






                         $.ajax({
                         type: "GET",
                                 cache:false,
                                 url: "https://www.ucloud.cn/yun/index.php?topic/ajaxaddsupport/" + tid,
                                 success: function(comments) {

                                 supportobj.find("span").html(comments+"人赞");
                                 }
                         });
                 }else{
                	 alert("您已经赞过");
                 }
                 }
         });
 });
 function attenquestion(_tid,_rs){
    	$.ajax({
    //提交数据的类型 POST GET
    type:"POST",
    //提交的网址
    url:"https://www.ucloud.cn/yun/favorite/topicadd.html",
    //提交的数据
    data:{tid:_tid,rs:_rs},
    //返回数据的格式
    datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
    //在请求之前调用的函数
    beforeSend:function(){},
    //成功返回之后调用的函数
    success:function(data){
    	var data=eval("("+data+")");
    	console.log(data)
       if(data.code==2000){
    	layer.msg(data.msg,function(){
    	  if(data.rs==1){
    	      //取消收藏
    	      $(".layui-layer-tips").attr("data-tips","收藏文章");
    	      $(".layui-layer-tips").html('<i class="fa fa-heart-o"></i>');
    	  }
    	   if(data.rs==0){
    	      //收藏成功
    	      $(".layui-layer-tips").attr("data-tips","已收藏文章");
    	      $(".layui-layer-tips").html('<i class="fa fa-heart"></i>')
    	  }
    	})
    	 
       }else{
    	layer.msg(data.msg)
       }


    }   ,
    //调用执行后调用的函数
    complete: function(XMLHttpRequest, textStatus){
     	postadopt=true;
    },
    //调用出错执行的函数
    error: function(){
        //请求出错处理
    	postadopt=false;
    }
 });
}
</script>
<footer>
        <div class="layui-container">
            <div class="flex_box_zd">
              <div class="left-footer">
                    <h6><a href="https://www.ucloud.cn/"><img src="https://www.ucloud.cn/yun/static/theme/ukd//images/logo.png" alt="UCloud (优刻得科技股份有限公司)"></a></h6>
                    <p>UCloud (优刻得科技股份有限公司)是中立、安全的云计算服务平台,坚持中立,不涉足客户业务领域。公司自主研发IaaS、PaaS、大数据流通平台、AI服务平台等一系列云计算产品,并深入了解互联网、传统企业在不同场景下的业务需求,提供公有云、混合云、私有云、专有云在内的综合性行业解决方案。</p>
              </div>
              <div class="right-footer layui-hidemd">
                  <ul class="flex_box_zd">
                      <li>
                        <h6>UCloud与云服务</h6>
                         <p><a href="https://www.ucloud.cn/site/about/intro/">公司介绍</a></p>
                         <p><a href="https://zhaopin.ucloud.cn/" >加入我们</a></p>
                         <p><a href="https://www.ucloud.cn/site/ucan/onlineclass/">UCan线上公开课</a></p>
                         <p><a href="https://www.ucloud.cn/site/solutions.html" >行业解决方案</a></p>                                                  <p><a href="https://www.ucloud.cn/site/pro-notice/">产品动态</a></p>
                      </li>
                      <li>
                        <h6>友情链接</h6>
                                             <p><a href="https://www.surfercloud.com/">SurferCloud</a></p>
                         <p><a href="https://ucloudstack.com/" >私有云</a></p><p><a href="https://pinex.it" >pinex</a></p> <p><a href="https://www.renyucloud.com/" ></a></p>                                                                                                     <p><a href="https://www.picpik.ai" >AI Art Generator</a></p>  <p><a href="https://www.uwin-link.com" >工厂仿真软件</a></p>                           
                      </li>
                      <li>
                        <h6>社区栏目</h6>
                         <p><a href="https://www.ucloud.cn/yun/column/index.html">专栏文章</a></p>
                         <p><a href="https://www.ucloud.cn/yun/ask/">专业问答</a></p>
                         <p><a href="https://www.ucloud.cn/yun/kc.html">云学院</a></p>
                     <p><a href="https://www.ucloud.cn/yun/udata/">专题地图</a></p>                      </li>
                      <li>
                        <h6>常见问题</h6>
                         <p><a href="https://www.ucloud.cn/site/ucsafe/notice.html" >安全中心</a></p>
                         <p><a href="https://www.ucloud.cn/site/about/news/recent/" >新闻动态</a></p>
                         <p><a href="https://www.ucloud.cn/site/about/news/report/">媒体动态</a></p>                                                  <p><a href="https://www.ucloud.cn/site/cases.html">客户案例</a></p>                                                
                         <p><a href="https://www.ucloud.cn/site/notice/">公告</a></p>
                      </li>
                      <li>
                          <span><img src="https://static.ucloud.cn/7a4b6983f4b94bcb97380adc5d073865.png" alt="优刻得"></span>
                          <p>扫扫了解更多</p></div>
            </div>
            <div class="copyright">Copyright © 2012-2023 UCloud 优刻得科技股份有限公司<i>|</i><a rel="nofollow" href="http://beian.miit.gov.cn/">沪公网安备 31011002000058号</a><i>|</i><a rel="nofollow" href="http://beian.miit.gov.cn/"></a> 沪ICP备12020087号-3</a><i>|</i> <script type="text/javascript" src="https://gyfk12.kuaishang.cn/bs/ks.j?cI=197688&fI=125915" charset="utf-8"></script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?290c2650b305fc9fff0dbdcafe48b59d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZSMXQ3P9N"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-DZSMXQ3P9N');
</script>
<script>
(function(){
var el = document.createElement("script");
el.src = "https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?99f50ea166557aed914eb4a66a7a70a4709cbb98a54ecb576877d99556fb4bfc3d72cd14f8a76432df3935ab77ec54f830517b3cb210f7fd334f50ccb772134a";
el.id = "ttzz";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(el, s);
})(window)
</script></div> 
        </div>
    </footer>
</body>
<script src="https://www.ucloud.cn/yun/static/theme/ukd/js/common.js"></script>
<<script type="text/javascript">
$(".site-seo-depict *,.site-content-answer-body *,.site-body-depict *").css("max-width","100%");
</script>
</html>