11

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.

1
  • Stuck with the same issue =\ Commented Jul 16, 2013 at 20:20

4 Answers 4

6

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)

Sign up to request clarification or add additional context in comments.

Comments

5

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

Comments

2

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

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

5 Comments

hey, its sound logical, but can you show the code that i need to add?
Sure, I'm traveling so on my mobile now; will post code when I get back to a computer. But basically it's just both of your files combined into one. If you don't want to wait for me to get back to a laptop just try it. :)
well i tried and could not make it work with apache, but now i managed to run it without apache, just used the run() command when apache is off, and still, i'll be happier if i'll be able to make it work with apache
Okay, looks like you took my suggestion (from another answer) and got it working, so I won't post any code now. Happy to hear you're all set.
There is no need to put the contents of hello.py into app.wsgi. Please check my answer on how this can be achieved.
1

i'm adding my conclusion for people who will have the same problem as i did: like Kneel-Before-ZOD and ron.rothman, i had to write my code in the WSGI file since python is running the code from there, BUT if you want to get your own py files you have to IMPORT them from the WSGI files like that:

from hello import application

the "hello" is the python FILE NAME and the "application" is the like you should write in you py file and NOT in wsgi:

application = bottle.default_app()

also had to restart apache every time i made a change(and i didn't know that - that why its made me crazy). tnx for the guys who helped me. GooLuck.

2 Comments

Just a tip: if you use bottle.run(reloader=True) then you won't have to restart apache every time you make a change.
unfortunately you cant use run with apache :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.