Alvin
Alvin

Reputation: 8499

apache2 mod_wsgi bottlepy NameError: name 'os' is not defined

I am trying to use apache2 mod_wsgi to deploy bottle.py web application.

I followed the instruction below:

http://bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi

Added a file /var/www/yourapp/app.wsgi:

# Change working directory so relative paths (and template lookup) work again
os.chdir(os.path.dirname(__file__))

import bottle
# ... build or import your bottle application here ...
# Do NOT use bottle.run() with mod_wsgi
application = bottle.default_app()

I added a file yourapp.py into /var/www/yourapp/:

from bottle import route, run, template

@route('/hello/:name')
def index(name='World'):
    return template('<b>Hello {{name}}</b>!', name=name)

Am I doing the right thing?

I get a Http 500 error, and found some error inside the log:

[Fri Feb 22 15:03:38 2013] [error] [client 192.168.0.104]     os.chdir(os.path.dirname(__file__))
[Fri Feb 22 15:03:38 2013] [error] [client 192.168.0.104] NameError: name 'os' is not defined
ke@dslds /var/log/apache2 $  NameError: name 'os' is not definedNameError: name 'os' is not defined

Upvotes: 0

Views: 1470

Answers (1)

jeffknupp
jeffknupp

Reputation: 6274

You need import os as the first line in your first file (app.wsgi). You're trying to use the os module without having first imported it.

Upvotes: 1

Related Questions