新浪云应用SAE配置Flask Python2.7 SVN

 新浪云SAE(新浪云应用SAE),主打的是轻应用轻服务,核心是服务。我们的目标是用其自带的Python2.7,将本地测试的代码传到应用中,并测试(开通服务)。
    创建应用,开发语言用Python共享环境,代码管理使用SVN,二级域名和应用名称可以自行配置。
图片
在其代码管理中,有代码管理和上传代码包。代码管理可用于单独修改一些文件,而上传代码包使用zip上传,就可以将重要的库一并上传,但是更多的时候可以考虑用SVN工具,见新浪云代码部署手册:http://www.sinacloud.com/doc/sae/tutorial/code-deploy.html
图片
最终的版本中,文件结构如下:
图片
site-packages文件夹里,是这个应用依赖的库,而templates文件夹里是测试用的html模板。
图片图片
config.yaml是这个app的信息:

name: on66

version: 1

index.wsgi文件可以理解为整个web的入口:

import    sae

sae.add_vendor_dir('site-packages') #依赖包位置

from index  import app

application = sae.create_wsgi_app(app)

test0.py是通过excel转化为序列结构的计算文件:

# encoding=utf-8 注释可用中文

import xlrd

def linkList():

    data = xlrd.open_workbook('link0321.xls')

    count = len(data.sheets())  # sheet数量

    dataList = []

    for sheet in data.sheets():

        table = data.sheet_by_name(sheet.name)

        itemList = []  # 构建内页的

        for i in range(table.nrows):

            itemList.append(table.row_values(i))

        infoDic = {sheet.name: itemList}

        dataList.append(infoDic)

    return dataList

 其中使用的link0321.xls结构如下:(数据量非常小,使用excel做数据源)
 图片


模板中使用的index0320.html文件如下:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<!-- 为了让 Bootstrap 开发的网站对移动设备友好,确保适当的绘制和触屏缩放,需要在网页的 head 之中添加 viewport meta 标签 -->

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>简洁 高效 快速</title>

<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">

<script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>

<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.js"></script>

<!--外联CSS样式-->

<style>

#head_space, #middle_space {

    height: 60px

}

#search {

    height: 35px

}

#button {

    text-align: center;

    padding-left: 10x;

    padding-right: 10px;

    height: 35px

}

.box1 {

    padding: 15px;

}

.box2 {

    background-color: white;

    padding: 15px;

}

.box3 {

    border-bottom-style: groove;

    border-bottom-color: #e6e6e6;

}

.box4 {

    padding-top: 10px;

    height: 30px;

    text-align: left;

}

</style>

</head>

<body style="background-color: rgba(135,165,117,0.20)">

<div class="container">

  <div class="row clearfix">

    <div class="col-md-12 col-sm-12 col-xs-12 col-lg-12" id="head_space">

        <h2>

            On66

        </h2>

    </div>

    <div class="col-md-12 col-sm-12 col-xs-12 col-lg-12" style="padding-left:80px;padding-right:80px"> 

      <!-- 百度搜索框代码开始 -->

      <form onsubmit="return baiduWithHttps(this)" action="http://www.baidu.com/baidu" target="_blank">

        <div class="col-md-8 col-sm-8 col-xs-8 col-lg-8" >

          <input name="tn" type="hidden" value="SE_zzsearchcode_shhzc78w">

          <input class="col-md-12 col-sm-12 col-xs-12 col-lg-12" id="search" type="text" onfocus="checkHttps" name="word"  size="30">

        </div>

        <input class="col-md-2 col-sm-2 col-xs-2 col-lg-2" id="button" type="submit" value="百度搜索">

      </form>

    </div>

  </div>

<!-- 链接框正文开始 -->

<!-- 这是一个基本的结构单元 -->

      {% for itemDic in dataList%}

    <div class="col-md-3 col-sm-6 col-xs-12 col-lg-4 box1">

      <div class="col-md-12 col-sm-12 col-xs-12 col-lg-12 box2">

        {% for key in itemDic %}

        <div class="col-md-12 col-sm-12 col-xs-12 col-lg-12 box3" >

          <h4> {{ key }}</h4>

        </div>

         {% for listLink in itemDic[key] %}

            <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4 box4"> <a href="{{listLink[1]}}" target="_blank">{{ listLink[0] }}</a> </div>

         {% endfor %}

      </div>

        {% endfor %}

    </div>

      {% endfor %}

      <!-- 这是一个基本的结构单元 -->

    <!-- 链接框正文结束 -->

  <!-- 百度搜索框javascript代码开始 --> 

  <script src="http://s1.bdstatic.com/r/www/cache/global/js/BaiduHttps_20150714_zhanzhang.js"></script> 

  <script>

    function checkHttps () {

        BaiduHttps.useHttps();    

    };

    function baiduWithHttps (formname) {

        var data = BaiduHttps.useHttps();

        if (data.s === 0) {

            return true;

        }

        else {

            formname.action = 'https://www.baidu.com/baidu' + '?ssl_s=1&ssl_c' + data.ssl_code;

            return true;

        }

    };

    </script> 

  <!-- 百度搜索框javascript代码结束 --> 

</div>

</body>

</html>

保存代码之后,就可以测试了,最终效果:
图片
其实很明显,这个做服务做API似乎更好吧,小快灵。

 参考资料:https://blog.csdn.net/qq_34963461/article/details/52936665

猜你喜欢

转载自blog.csdn.net/limaning/article/details/81626135