【发布时间】:2014-07-14 15:18:57
【问题描述】:
我是整个 mod_wsgi 和通过 apache 提供文件的新手。我对烧瓶真的很满意,但这是我无法理解的。我做了hello-world程序,成功展示了hello world! 现在我想显示一个图像文件。所以我将我的 hello-world.py 更新为:
from flask import *
yourflaskapp = Flask(__name__)
@yourflaskapp.route("/")
def hello():
file="203.jpg"
return render_template("hello.html",file=file)
# return"HEY"
if __name__ == "__main__":
yourflaskapp.run()
我的目录结构类似于:/var/www/hello-world
/hello-world
test.py
yourflaskapp.wsgi
/static
-203.jpg
/templates
-hello.html
我的模板很简单:
<!DOCTYPE html>
<html><head><title>hi</title></head>
<body>
<img src="{{url_for('static',filename=file)}}"/>
</body></html>
我的 apache conf 文件是:
<VirtualHost *:80>
WSGIDaemonProcess yourflaskapp
WSGIScriptAlias / /var/www/hello-world/yourflaskapp.wsgi
Alias /static/ /var/www/hello-world/static
Alias /templates/ /var/www/hello-world/templates
<Directory /var/www/hello-world>
WSGIProcessGroup yourflaskapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/hello-world/static>
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/hello-world/templates>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
虽然当我打开浏览器并转到我的 ip 时,它并没有显示图像文件。 我究竟做错了什么?我应该遵循其他方法吗? 如果有人可以推荐任何我可以理解使用flask+mod_wsgi+apache2的好的链接
【问题讨论】:
-
直接点击
{your-ip}/static/203.jpg会发生什么?
标签: python static flask apache2 mod-wsgi