running Apache + Bottle + Python

后端 未结 4 1759
夕颜
夕颜 2020-12-16 01:20

I\'m trying to run Bottle.py with Apache and mod_wsgi.

I\'m running it on windows, using a xampp. python v2.7

My Apache config in httpd:

<         


        
4条回答
  •  孤城傲影
    2020-12-16 01:57

    Or Duan's comments were a good starting point for me to separate the app.wsgi and the application python file. But they were a little cryptic for me to understand. After messing around for a couple of hours, here is what worked for me:
    [BTW, I am working on OSX. Please adjust the paths, user, group according to your operating system]

    /Library/WebServer/Documents/hello_app/app.wsgi:

    import sys
    
    sys.path.insert(0, "/Library/WebServer/Documents/hello_app")
    
    import bottle
    import hello
    application = bottle.default_app()
    

    /Library/WebServer/Documents/hello_app/hello.py:

    from bottle import route
    
    @route('/hello')
    def hello():
        return "Hello World!"
    

    /etc/apache2/extra/httpd-vhosts.conf:

    
        ServerName xyz.com
    
        WSGIDaemonProcess hello_app user=_www group=_www processes=1 threads=5
        WSGIScriptAlias /v1 /Library/WebServer/Documents/hello_app/app.wsgi
    
        
            WSGIProcessGroup hello_app
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
        
    
    

    Don't forget to restart your apache server.

    Check the app in the web browser

提交回复
热议问题