views.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:jawaf 作者: danpozmanter 项目源码 文件源码
def get(self, request, table_name=None):
        """Get endpoint. Retrieve one object by id (url param `id=`)
        :param request: Sanic Request.
        :param table_name: Name of the table to access.
        """
        waf = get_jawaf()
        table = registry.get(table_name)
        try:
            target_id = int(request.raw_args.get('id', None))
        except:
            return json({'message': 'no id'}, status=400)
        if not table:
            return json({'message': 'access denied'}, status=403)
        async with Connection(table['database']) as con:
            query = sa.select('*').select_from(table['table']).where(table['table'].c.id==target_id)
            result = await con.fetchrow(query)
            if not result:
                return json({'message': 'not found', 'data': None}, status=404)
            return json({'message': 'success', 'data': result}, status=200)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号