Reputation: 91
I'm trying to use sessions on a small CMS that I'm working on.
I'm testing, and I able to run sessions nicely using bottle as server. Code below:
# test.session.py
import bottle
from beaker.middleware import SessionMiddleware
session_opts = {
'session.type': 'file',
'session.cookie_expires': 300,
'session.data_dir': './data',
'session.auto': True
}
app = SessionMiddleware(bottle.app(), session_opts)
@bottle.route('/set_session')
def session_test():
varsession = bottle.request.environ.get('beaker.session')
varsession['value1'] = 'This is the value'
return varsession['value1']
@bottle.route('/get_session')
def sessao():
varsession = bottle.request.environ.get('beaker.session')
return varsession['value1']
bottle.run(app=app)
But I'm using Apache + modwsgi to run this CMS. And I'm bit confused where should I place imports etc... Should I put into the “adapter.wsgi” or should I place into the “.py” file?
# WSGI.file
import sys, os, bottle
sys.path = ['/filmes/appone'] + sys.path
os.chdir(os.path.dirname(__file__))
import appone # This loads your application
application = bottle.default_app()
# .py file
import bottle
from bottle import route, request, debug
from beaker.middleware import SessionMiddleware
session_opts = {
'session.type': 'file',
'session.cookie_expires': 300,
'session.data_dir': './data',
'session.auto': True
}
app = SessionMiddleware(bottle.app(), session_opts)
@route('/')
def funcone():
return "Home Page"
@route('/session_test')
def session_test():
varsession = bottle.request.environ.get('beaker.session')
varsession['value1'] = 'This is the value'
return varsession['value1']
I got a 500 error. And that's all I got.
By the way, where should I set debug True on Apache + WSGI?
I'm kind of new on Bottle/Python....
Upvotes: 1
Views: 2362
Reputation: 159
This is how I will modify your # WSGI.file
import os
os.chdir('/filmes/') # the directory where your py files are, use the full linux system path
from appone import app # I assume appone.py is your main application
application = app
You are referencing the default_app(), which was replaced by app when you implement session in your code.
Upvotes: 1