简体   繁体   中英

Apache web server giving 404 when trying to deploy Flask on it

I'm trying to deploy my flask application on a Windows Server 2012. I'm following the instructions here to the point: https://claudiosparpaglione.wordpress.com/2013/03/06/how-to-deploy-flask-applications-to-apache-webserver/

Now, this is my apache config file (relevant bits):

Listen 5060
LoadModule wsgi_module modules/mod_wsgi.so
<Directory C:/FlaskOnApache>
    Require all granted
</Directory>
WSGIScriptAlias /api C:/FlaskOnApache/flasky.wsgi

When I go to:

http://localhost:5060/

I get the "It works!" page.

But when I go to http://localhost:5060/api/hello?name=claudio I get a 404.

What am I doing wrong?

Error.log gives me this:

Target WSGI script not found or unable to stat: C:/FlaskOnApache/flasky.wsgi

But it is definitely present there and is the copy of what is mentioned in the link above.

Edit:

My flasky.py file:

from flask import Flask, request
app = Flask(__name__)

@app.route('/hello')
def hello_world():
    name = request.args.get('name','')
    return 'Hello ' + name + '!'
if __name__ == '__main__':
    app.run()

My flasky.wsgi.py file:

import sys

#Expand Python classes path with your app's path
sys.path.insert(0, "C:/FlaskOnApache")

from flasky import app

#Put logging code (and imports) here ...

#Initialize WSGI app object
application = app

在Flask app.py中,您需要将路由从: @app.route('/')为:

`@app.route('/hello')

Silly mistake. Got it working. The file name is supposed to be "flasky.wsgi" not "flasky.wsgi.py". Thanks guys!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM