【问题标题】:Bottle + Apache + WSGI + Sessions瓶 + Apache + WSGI + 会话
【发布时间】:2013-07-12 14:45:22
【问题描述】:

我正在尝试在我正在开发的小型 CMS 上使用会话。

我正在测试,我能够使用瓶子作为服务器很好地运行会话。代码如下:

# 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”文件?

#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?

我对 Bottle/Python 有点陌生......

【问题讨论】:

  • 500 错误 - 您在 error_log 中看到了什么?那里会有一个堆栈跟踪,这将有助于追踪问题。

标签: python session wsgi bottle


【解决方案1】:

这就是我将如何修改你的#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 替换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    相关资源
    最近更新 更多