Python:Flask视图函数没有返回响应

时间:2017-07-20 09:21:05

标签: python-3.x flask

我正在尝试运行一个以资源和帐户作为参数的Web服务并返回用户密码,但它会返回一些错误:

raise ValueError('View function did not return a response')
ValueError: View function did not return a response

这是我的代码的结构:

from flask import Flask
import requests

# Config
TOKEN = "" 
SERVER = "" 

# Classes
class PClient():
    def __init__(self, token=TOKEN, server=SERVER):
        self.token = token
        self.server = server 
        self.cache = {} 
        pass

    def getPassword(self, resource, account):
        if resource in self.cache and account in self.cache[resource]:
            return self.cache[resource][account]
        else :
            return "Something"

# Script
app = Flask(__name__) 
pmp = PClient() 

@app.route('/<string:resource>/<string:account>')
def get_password(resource, account):
    global pmp
    return pmp.getPassword(resource, account)

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=2999, debug=True) 

任何想法? 谢谢

1 个答案:

答案 0 :(得分:0)

根据Flask source,您的视图函数返回None。您需要检查将值插入self.cache[resource][account]

的代码