瓶+ Apache + WSGI +会话 [英] Bottle + Apache + WSGI + Sessions
问题描述
我正在尝试在正在使用的小型CMS上使用会话。
I'm trying to use sessions on a small CMS that I'm working on.
我正在测试,并且能够使用Bottle很好地运行会话作为服务器。下面的代码:
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)
但是我使用Apache + modwsgi运行此CMS。而且我有些困惑,应该在哪里放置导入文件等...应该放入 adapter.wsgi还是应该放入 .py文件?
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
# 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']
我遇到500错误。
顺便问一下,我应该在哪里在Apache + WSGI上设置debug True?
By the way, where should I set debug True on Apache + WSGI?
我是Bottle / Python的新手。...
I'm kind of new on Bottle/Python....
推荐答案
这就是我将修改#WSGI的方式。文件
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
您引用的是default_app(),当您在代码中实现会话时,它将由app替换。
You are referencing the default_app(), which was replaced by app when you implement session in your code.
这篇关于瓶+ Apache + WSGI +会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!