小编Lal*_*mar的帖子

Flask after_request'NonType'对象不可调用

我有一个非常繁重的应用程序建立在flask-restful上,所以我将在这里展示问题的较小版本.我将我的应用程序划分为具有该结构的模块

Folder A:  
    __init__.py (empty)
    main-file.py (executable file)
    other-file.py  
Run Code Online (Sandbox Code Playgroud)

other-file.py

from flask_restful import reqparse, abort, Api, Resource
from flask import Flask

TODOS = {
'todo1': {'task': 'build an API'},
'todo2': {'task': '?????'},
'todo3': {'task': 'profit!'},
}
class TodoList(Resource):
    def get(self):
        return TODOS  
Run Code Online (Sandbox Code Playgroud)

main-file.py

from flask import Flask,request
from  other-file import *

app = Flask(__name__)
api = Api(app)

@app.before_request
def before_request():
    print 'before request'

@app.after_request         #This block fails
def after(response):
    print 'after request'
    #I need to perform some db operations here …
Run Code Online (Sandbox Code Playgroud)

python flask

3
推荐指数
1
解决办法
1877
查看次数

标签 统计

flask ×1

python ×1