我得到了405:方法不允许,那么问题在哪里,它是一个 post方法,因为我想把数据发送到服务器
class VendreHandler(BaseHandler):
@tornado.web.authenticated
def post(self):
self.db = conn["essog"]
user = self.get_secure_cookie("mechtari")
info = tornado.escape.json_decode(user)
email = info["email"]
namep = self.get_argument("namep")
prix = self.get_argument("prix")
description = self.get_argument("description")
date = datetime.datetime.now().date()
try:
photo = self.request.files['photo'][0]["body"]
try:
avctype = self.request.files['avatar'][0]["content_type"]
image = Image.open(StringIO.StringIO(buf=avat))
type = image.format
(x, y) = image.size
if x < y:
orientation = "portrait"
else:
orientation = "paysage"
pref = str(time.time())
nomfi = pref.replace(".", "")
nomfich = nomfi + "-" + self.request.files['avatar'][0]["filename"]
self.fs = GridFS(self.db)
avatar_id = self.fs.put(avat, content_type=avctype,filename=nomfich)
except IOError, TypeError:
self.redirect("/error-im")
except KeyError:
nomfich = "nofile"
orientation = "paysage"
avctype = "image/jpeg"
avatar_id = '503ae8553a5f3a0dd8b9cb4c'
self.db.users.update({"email":email}, {"$set":{"produit_up.namep":namep,"produit_up.prix":prix,"produit_up.photo":photo_id, "produit_up.description":description,"produit_up.date":date, "produit_up.vendu":False}})
self.redirect("/success")
以及模板:
^{pr2}$我把处理程序简化为
class VendreHandler(tornado.web.RequestHandler):
def post(self):
namep = 1
prix = 3
description = 43
date = 345
self.db = conn["essog"]
self.db.users.update({"email":email}, {"$set":{"produit_up.namep":namep,"produit_up.prix":prix, "produit_up.photo":photo_id, "produit_up.description":description,"produit_up.date":date, "produit_up.vendu":False}})
self.redirect("/profil#vendu")
总是方法错误它根本没有检查处理程序的内容 (否则在找不到电子邮件时出现错误)!在
解决了! 问题似乎来自picture处理程序;在URLSpec中,它必须是列表中的最后一个
这就是为什么在使用GET方法时返回有关图片的错误! 希望这会有所帮助,谢谢:)
相关问题 更多 >
编程相关推荐