Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1752269
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 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']('')
```python
import this
The Zen of Python, by Tim Peters ...
```
安装测试完成。

2. nginx+flask+jinja2安装配置
下载[nginx](''),解压
修改配置文件nginx.conf port=8080,start nginx.exe
``
>Welcome to nginx!
>..........
install['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

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

>
下载[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]('')
*The Swiss Army knife of Python web development*
```sh
python setup.py install
```
*Finished processing dependencies for Werkzeug==0.11.9*

下载[flask]('')
···

(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]('')
ref[config]('')
gunicorn 仅支持*NIX*平台[gunicorn]('')
flask 官网推荐[uWSGI]('')这里我们也对uWGSI进行配置。
download [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]('')
python [driver]('')
`(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]('')

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

```python
import cx_Oracle as cx
conn=cx.connect()
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[]('')
关于
##3下载地址
1. [echarts]('','abc')
2. [jinja2]('')
3. [flask2]('')
4. [nginx]('')
5. [nginx2]('en/docs/http/ngx_http_uwsgi_module.html')


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