Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running Apache + Bottle + Python

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:

<VirtualHost *>
    ServerName example.com
    WSGIScriptAlias / C:\xampp\htdocs\GetXPathsProject\app.wsgi
    <Directory C:\xampp\htdocs\GetXPathsProject>
            Order deny,allow
            Allow from all
    </Directory>
</VirtualHost>

My app.wsgi code:

import os
os.chdir(os.path.dirname(__file__))
import bottle
application = bottle.default_app()

My hello.py:

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

When I go to localhost/hello I get a 404 error. I don't have any other errors on the Apache log file, probably missing something basic.

like image 920
Or Duan Avatar asked Jul 16 '13 13:07

Or Duan


Video Answer


3 Answers

There's no connecting point from your wsgi file to your hello.py file.
Put the content in your hello.py into the app.wsgi and restart your web server.
That should resolve the problem.

To make your application modular such that you can put the code into various files, check out Bottle's equivalent of Blueprints (used by Flask framework)

like image 71
Kneel-Before-ZOD Avatar answered Oct 09 '22 06:10

Kneel-Before-ZOD


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:

<VirtualHost *:80>
    ServerName xyz.com

    WSGIDaemonProcess hello_app user=_www group=_www processes=1 threads=5
    WSGIScriptAlias /v1 /Library/WebServer/Documents/hello_app/app.wsgi

    <Directory /Library/WebServer/Documents/hello_app>
        WSGIProcessGroup hello_app
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

Don't forget to restart your apache server.

Check the app in the web browser

like image 5
leodotcloud Avatar answered Oct 09 '22 04:10

leodotcloud


I don't see your hello.py referenced anywhere.

You should just put the contents of hello.py (the route) into app.wsgi.

like image 2
ron rothman Avatar answered Oct 09 '22 05:10

ron rothman