전 mod_wsgi에 익숙하지 않고 아파치를 통해 파일을 제공합니다. 나는 플라스크에 정말로 편안하지만 이것은 내 머리를 얻을 수없는 무언가이다. 나는 안녕하세요 - 세계 프로그램을하고 성공적으로 안녕하세요 세상을 표시! 이제 이미지 파일을 표시하려고했습니다. 그래서 난 내 hello-world.py 업데이트의 경우 :/var/www /에서 안녕하세요 세계아파치를 통해 정적 파일 제공
/hello-world
test.py
yourflaskapp.wsgi
/static
-203.jpg
/templates
-hello.html
내 템플릿은 간단하다 :
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()
내 디렉토리 구조는 무엇인가 등이
<!DOCTYPE html>
<html><head><title>hi</title></head>
<body>
<img src="{{url_for('static',filename=file)}}"/>
</body></html>
내 아파치의 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로 향하면 이미지 파일이 표시되지 않습니다. 내가 뭘 잘못 했니? 내가 따라야 할 다른 방법이 있습니까? 누군가가 플라스크 + mod_wsgi + apache2로 작업하는 것을 이해할 수있는 좋은 링크를 추천 할 수 있다면
당신이 /가 직접 203.jpg'/{당신의-IP}'정적 쳤을 때 어떻게됩니까? –