代码:
蓝图:
from flask import Blueprint
from flask_restful import Api
################################
### Local Imports ###
################################
profile_api = Blueprint('profile_api', __name__)
api = Api(profile_api)
from .views import *视图:
class ShowProfPic(Resource):
def get(self):
return "hey"
api.add_resource(ShowProfPic, '/get profile picture/',endpoint="showpic") 我们怎么用flask_restful?做url_for,因为当我这样做的时候。
这是一个路由错误,当我使用url_for('api.ShowProfPic')时,它仍然是一个路由错误
发布于 2016-01-05 05:53:06
我已经知道答案了。
显然,在使用blueprints时
访问flask_restful's url_for的方法是
url_for('blueprint_name.endpoint)
意味着必须在资源上指定终结点
所以使用上面的例子:
profile_api = Blueprint('profile_api', __name__)
api = Api(profile_api)
from .views import *
class ShowProfPic(Resource):
def get(self):
return "hey"
api.add_resource(ShowProfPic, '/get profile picture/',endpoint="showpic") 要引用ShowProfPic类并获取它的endpoint,它是url_for('blueprint_name.endpoint'),所以这是url_for(profile_api.showpic)
https://stackoverflow.com/questions/34599881
复制相似问题