天天看點

tornado ajax post,python中使用tornado 中post get 請求報錯500

我用tornado寫了兩個接口,第一個沒有問題,然後我吧第一個複制到第二個檔案裡就報錯了

第一個接口代碼如下:

import tornado

from wtforms_tornado import Form

import sys

from app.view.view_xxm.mysqlfuntion import selectnav

class hello(tornado.web.RequestHandler):

def get(self):

self.render("hello.html")

class ajaxtest(tornado.web.RequestHandler):

def set_default_headers(self):

print("setting headers!!!")

self.set_header("Access-Control-Allow-Origin", "*")

self.set_header("Access-Control-Allow-Headers", "x-requested-with")

self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')

def get(self):

import json

type1 = self.get_argument("type")

print(type1)

data = [{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}]

data1 = selectnav(type1)

res=dict()

res=[

dict(

id=k.id,

imgurl=k.imgurl,

link=k.link,

title=k.title,

type=k.type,

addtime=k.addtime

)for k in data1

]

print(res)

json = json.dumps(res).encode("utf-8").decode('unicode_escape')

self.write(json)

# data="你好我是劉德華天涯何處無芳草"

# # data.encode("utf-8")

# # print("get")

# # self.write(data)

第二個接口代遇新是直朋能到分覽碼如下

import tornado

from wtforms_tornado import Form

import sys

from app.view.view_xxm.mysqlfuntion import selectnav

class hello(tornado.web.RequestHandler):

def get(self):

self.render("hello.html")

class selectnav(tornado.web.RequestHandler):

def set_default_headers(self):

print("setting headers!!!")

self.set_header("Access-Control-Allow-Origin", "*")

self.set_header("Access-Control-Allow-Headers", "x-requested-with")

self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')

def post(self):

import json

type1 = self.get_argument("type")

print(type1)

data = [{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}]

data1 = selectnav(type1)

res=dict()

res=[

dict(

id=k.id,

imgurl=k.imgurl,

link=k.link,

title=k.title,

type=k.type,

addtime=k.addtime

)for k in data1

]

print(res)

json = json.dumps(res).encode("utf-8").decode('unicode_escape')

self.write(json)

# data="你好我是劉德華天涯何處無芳草"

# # data.encode("utf-8")

# # print("get")

# # self.write(data)

報錯資訊如下:

tornado ajax post,python中使用tornado 中post get 請求報錯500

完整代碼下載下傳位址

下載下傳位址

接需朋者說上事是礎一發一開程和開數的目前間口路由是ajax和xx新直能分支調二浏頁器朋代說,事剛m這兩個