Fork me on GitHub
Suzf  Blog

Tag Flask

How-to deploy flask web applications use wsgi behind apache

Flask是一个使用Python编写的轻量级Web应用框架。基于Werkzeug WSGI工具箱和Jinja2 模板引擎Flask使用BSD授权。 Flask也被称为“microframework”,因为它使用简单的核心,用extension增加其他功能。Flask没有默认使用的数据库、窗体验证工具。然而,Flask保留了扩增的弹性,可以用Flask-extension加入这些功能:ORM、窗体验证工具、文件上传、各种开放式身份验证技术。 WSGI Web服务器网关接口Python Web Server Gateway Interface,缩写为WSGI)是为Python语言定义的Web服务器Web应用程序框架之间的一种简单而通用的接口。自从WSGI被开发出来以后,许多其它语言中也出现了类似接口。

How-to resolve Target WSGI script xxx.wsgi cannot be loaded as Python module

情景再现: 在我将 Flask应用程序部署到 Apache 的时候,我得到了一个  500 internal sever error 的错误。 查看错误日志得到下面信息

[Tue Jun 21 11:29:46 2016] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips mod_wsgi/3.2 Python/2.7.3 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming #
[Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] mod_wsgi (pid=1334): Target WSGI script '/var/www/html/report/report.wsgi' cannot be loaded as Python module.
[Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] mod_wsgi (pid=1334): Exception occurred processing WSGI script '/var/www/html/report/report.wsgi'.
[Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] Traceback (most recent call last):
[Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158]   File "/var/www/html/report/report.wsgi", line 10, in <module>
[Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158]     from report import app as application
[Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158]   File "/var/www/html/report/report.py", line 11, in <module>
[Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158]     from flask import Flask
[Tue Jun 21 11:29:49 2016] [error] [client 172.16.7.158] ImportError: No module named falsk

Python 应用程序是 通过源码编译的,安装目录为 /usr/local/Python2.7.3 Flask 模块是存在的, 问题就在 为啥 找不到她呢???

How to limit Flask dev server to only one visiting ip address

I'm developing a website using the Python Flask framework and I now do some devving, pushing my changes to a remote dev server. I set this remote dev server up to serve the website publically using app.run(host='0.0.0.0').

This works fine, but I just don't want other people to view my website yet. For this reason I somehow want to whitelist my ip so that the dev server only serves the website to my own ip address, giving no response, 404's or some other non-useful response to other ip addresses. I can of course set up the server to use apache or nginx to actually serve the website, but I like the automatic reloading of the website on code changes for devving my website