[英]Unable to access endpoint on flask api
我正在尝试使用flask和flask-restplus构建一个api,它似乎没有错误。 当我启动服务器时,它看起来像这样 但是无论 uri 是什么,我都尝试测试,它显示requested URL was not found on the server
并且知道如何运行相应的资源。 这是我的代码示例
@api.route('/')
class UserList(Resource):
@api.doc('list_of_registered_users')
@admin_token_required
@api.marshal_list_with(_user, envelope='data')
def get(self):
"""List all registered users"""
logger.debug('Hello from webapplib!')
return userService.get_all()
@api.expect(_user, validate=True)
@api.response(201, 'User successfully created.')
@api.doc('create a new user')
def post(self):
"""Creates a new User """
data = request.json
return save_new_user(data=data)
这是在黑暗中拍摄,但也许就是这么简单。
我假设您正在访问/user
。 在您的代码示例中, UserList
的装饰器是@api.route('/')
,它对应于http://127.0.0.1:5000/
在开发服务器中运行@api.route('/')
时(可能带有一些 API 版本路径appendend,但让我们暂时忽略它)。
你有没有试过用@api.route('/user')
而不是/
来装饰它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.