my home


  • 首页

  • 归档

  • 标签

在windows下部署flask

发表于 2016-04-05

1、安装python3 64位

2、安装virtualenv

1
pip install virtualenv

3、启动virtualenv Script/activate.bat

4、(env)pip install flask

5、编写wsgi.wsgi

1
2
3
4
5
import sys
sys.path.insert(0,'c:/web')
sys.path.insert(0,'c:\web\env\lib\site-packages')
from main import app
application = app

6、安装apache 64 vc11

7、下载mod_wsgi.so(必须对应版本) copy到Apache24\modules文件夹下

8、配置http.conf

1
2
LoadModule wsgi_module modules/mod_wsgi.so
Include conf/extra/httpd-vhosts.conf

9、配置httpd-vhosts.conf

1
2
3
4
5
6
7
8
<VirtualHost *:5000>  
WSGIScriptAlias / c:\web\wsgi.wsgi
#DocumentRoot c:\web
<Directory "c:\web">
Require all granted
Require host ip
</Directory>
</VirtualHost>

python3 文件操作

发表于 2016-03-05

python3 文件操作

  • 读写文件

    1
    2
    3
    4
    5
    6
    7
    8

    with open('somefile.txt', 'rt') as f:
    data = f.read()


    text = 'some words'
    with open('somefile.txt', 'wt') as f:
    data = f.write(text)
  • 文件不存在才能写入

    可以在 open() 函数中使用 x 模式来代替 w 模式的方法来解决这个问题

    1
    2
    with open('somefile.txt', 'xt') as f:
    data = f.write('hello world!\n')
hf

hf

2 日志
© 2016 hf
由 Hexo 强力驱动
主题 - NexT.Pisces