【发布时间】:2012-10-12 16:08:40
【问题描述】:
在加载我的烧瓶应用程序之前,我需要从 wsgi 请求中读取一些值。如果我从 wsgi 请求中读取 url,一旦加载了烧瓶应用程序(在中间件运行之后),我就可以毫无问题地访问该文件。
但是,如果我尝试访问参数,一旦加载烧瓶应用程序,它似乎会删除发布数据。我什至用一个特殊的 Webob 请求来包装 wsgi 请求,以防止这种“读取一次”问题。
有谁知道如何在中间件中访问 wsgi 请求中的值,而不会对请求造成任何副作用,因此您可以在烧瓶应用程序中获取发布数据/文件数据?
from webob import Request
class SomeMiddleware(object):
def __init__(self, environ):
self.request = Request(environ)
self.orig_environ = environ
def apply_middleware(self):
print self.request.url #will not do any harm
print self.request.params #will cause me to lose data
这是我的烧瓶视图
@app.route('/')
def hello_world():
from flask import request
the_file = request.files['file']
print "and the file is", the_file
【问题讨论】:
标签: python python-2.7 flask wsgi webob