# -*- coding: utf-8 -*-
from flask import request, jsonify, json, Module
import logging
from web.utils.consts import POST, GET
from web.db.dbSession import DBManager
from web.db.models import Class
NAMESPACE = 'student'
student = Module(__name__, NAMESPACE)
@student.route('/add', methods=[POST])
def student_add():
# request.json 只能够接受方法为POST、Body为raw,header 内容为 application/json类型的数据:对应图1
# json.loads(request.dada) 能够同时接受方法为POST、Body为 raw类型的 Text
# 或者 application/json类型的值:对应图1、2
params = request.json if request.method == "POST" else request.args
try:
session = DBManager.get_session()
c = Class(name=params['name'])
session.add(c)
session.commit()
session.close()
except Exception, e:
logging.exception(e)
return jsonify(code=200, status=0, message='ok', data={})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
图一
图二
---------------------
作者:不设限
来源:CSDN
原文:https://blog.csdn.net/tengdazhang770960436/article/details/80106533
版权声明:本文为博主原创文章,转载请附上博文链接!