Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1406652
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4337
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: Python/Ruby

2016-05-24 21:53:21

#web项目开发手记-环境搭建
##1开发清单列表
1. 开发平台:windows
2. 开发语言:python 2.7
3. 开发框架:flask+jinja2
4. 前端框架:bootstrap+jquery+echarts+...
5. 缓存系统:redis
6. 服务器  :nginx
6. 数据库系统:oracle/mysql/redis
7. 开发工具:sublime
8. 文档语言:markdown

##2软件配置过程
1. python安装
download url['python']('http://www.xiazaiba.com/html/2049.html')
```python
import this
The Zen of Python, by Tim Peters ...
```
安装测试完成。

2. nginx+flask+jinja2安装配置
下载[nginx]('http://nginx.org/download/nginx-1.9.15.zip'),解压
修改配置文件nginx.conf port=8080,start nginx.exe
`http://127.0.0.1:8080/`
>Welcome to nginx!
>..........
install['virtualenv']('https://pypi.python.org/pypi/virtualenv/')
```sh
python setup.py install
*Finished processing dependencies for virtualenv==15.0.1*
*path*;C:\Python27\Scripts   **必需将path添加至环境变量**
```


```python
H:\webabc>virtualenv venv
New python executable in H:\webabc\venv\Scripts\python.exe
Installing setuptools, pip, wheel...done.
H:\webabc>mkdir flask
H:\webabc>virtualenv --version
```

```python
https://pypi.python.org/pypi/itsdangerous/0.24
(venv) H:\webtools\itsdangerous-0.24>python setup.py install
```

>
下载[jinja2]('https://pypi.python.org/pypi/Jinja2')
*Jinja2 is a templating engine for Python*
```python
(venv) H:\webtools\Jinja2-2.8>python setup.py install
```
*Finished processing dependencies for Jinja2==2.8*
下载[Werkzeug]('https://pypi.python.org/pypi/Werkzeug')
*The Swiss Army knife of Python web development*
```sh
python setup.py install
```
*Finished processing dependencies for Werkzeug==0.11.9*

下载[flask]('https://pypi.python.org/pypi/Flask/0.10.1')
···

(venv) H:\webtools\Flask-0.10.1>python setup.py install
···
*Finished processing dependencies for Flask==0.10.1*
flask test:
```python
from flask import Flask
app=Flask(__name__)

@app.route("/")
def index():
  return "this is my first flask program"
if __name__=='__main__' :
  app.run()
```

3.  配置nginx,flask,gunicorn
wsgi的优劣讨论在这里[A Comparison of Web Servers for Python Based Web Applications]('https://www.digitalocean.com/community/tutorials/a-comparison-of-web-servers-for-python-based-web-applications')
ref[config]('https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-14-04')
gunicorn 仅支持*NIX*平台[gunicorn]('http://docs.gunicorn.org/en/stable/')
flask 官网推荐[uWSGI]('http://flask.pocoo.org/docs/0.10/deploying/uwsgi/')这里我们也对uWGSI进行配置。
download [uwsgi]('https://pypi.python.org/pypi/uWSGI')
**cofnig nginx**

```python           
        location / {
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:9090   #pass every request to the server bound to port 9090 speaking the uwsgi protoco
            root   html;
            index  index.html index.htm;
        }
```


4.  redis 安装配置
[windows redis version]('www.newasp.net/soft/67186.html#downloaded')
python [driver]('https://pypi.python.org/pypi/redis/2.10.5#downloads')
`(venv) H:\webtools\redis-2.10.5>python setup.py install`

```python
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=0)
print r.set('foo', 'bar')
print r.get('foo')
```


>(venv) H:\webabc\flask\venv>python testredis.py
True
bar


6. oracle 测试
python [oracle driver]('https://pypi.python.org/pypi/cx_Oracle/5.2.1')

```shell
C:\Windows\system32>net start OracleServiceRMFDB
OracleServiceRMFDB 服务正在启动 ...................
OracleServiceRMFDB 服务已经启动成功。
C:\Windows\system32>lsnrctl start
```
测试用例

```python
import cx_Oracle as cx
conn=cx.connect('system/kinfinger@RMFDB')
cursor=conn.cursor()
cursor.execute('select * from v$version')
resultset=cursor.fetchall()
for row in resutlset:
  print row
resultset.close()
```
>H:\webabc\flask\venv>python testora.py
('Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production',)
('PL/SQL Release 11.2.0.1.0 - Production',)
('CORE\t11.2.0.1.0\tProduction',)
('TNS for 32-bit Windows: Version 11.2.0.1.0 - Production',)
('NLSRTL Version 11.2.0.1.0 - Production',)

cx_Oracle USER GUIDE[]('http://cx-oracle.readthedocs.io/en/latest/index.html')
关于
##3下载地址
1. [echarts]('http://echarts.baidu.com/echarts2/index.html','abc')
2. [jinja2]('https://pypi.python.org/pypi/Jinja2')
3. [flask2]('http://docs.jinkan.org/docs/flask/')
4. [nginx]('http://nginx.org/')
5. [nginx2]('http://nginx.org/en/docs/http/ngx_http_uwsgi_module.html')


阅读(1867) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~