I am new to mod_wsgi and serve files via apache. I really like the flask, but this is something that I cannot omit. I made the hello-world program and successfully showed hello to the world! Now I wanted to display the image file. So I updated my hello-world.py to:
from flask import *
yourflaskapp = Flask(__name__)
@yourflaskapp.route("/")
def hello():
file="203.jpg"
return render_template("hello.html",file=file)
if __name__ == "__main__":
yourflaskapp.run()
my directory structure is something like: / var / www / hello-world
/hello-world
test.py
yourflaskapp.wsgi
/static
-203.jpg
/templates
-hello.html
My template is simple:
<!DOCTYPE html>
<html><head><title>hi</title></head>
<body>
<img src="{{url_for('static',filename=file)}}"/>
</body></html>
and my apache conf file:
<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>
Although, when I open the browser and head to my ip, it does not display the image file. What am I doing wrong? Is there any other approach I should follow? and if anyone can recommend any good links, how can I understand working with a jar + mod_wsgi + apache2