Reputation: 4440
i get the 405: Method Not Allowed, so where is the problem, it's a post method since i want to send data to the server
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")
and the template:
<form id="formvente" name="formvente" method="post" action="/vendre" enctype="multipart/form-data">
{% raw xsrf_form_html() %}
<label for="namep">Le nom du Produit</label>
<input type="text" name="namep" required title="vous devez mettre le nom du produit" placeholder="exemple: peugeot 206">
<label for="prix">Son prix (en Dinars Algérien)</label>
<input type="number" name="prix" required title="vous devez mettre le prix en chiffre (en Dinars Algérien)" placeholder="exemple: 800000">
<label for="photo">Une photo de votre produit</label>
<input name="photo" type="file">
<label for="description">Veuillez donner une déscription du produit (maximum 160 caractères)</label>
<textarea name="description" id="description" rows="3" cols="60" required title="vous devez mettre une petite description" placeholder="escence, 2006, roulant 100000km, toutes options, siege en cuir" onKeyDown="textCounter(document.formvente.description,160)" onKeyUp="textCounter(document.formvente.description, 160)"></textarea>
<meter name="shower" min="1" max="160" value="1"id="shower" low="30" high="140">afficher son etat</meter>
<input id="vendre" type="submit" value="Mettre en Vente"/>
</form>
and i have simplified the handler to this
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")
always the method error it dident check the handler content at all (else it raised and error when not finding email)!
Upvotes: 2
Views: 2293
Reputation: 4440
SOLVED! it seems that the problem is coming from the picture handler; in the URLSpec, IT MUST BE THE LAST ONE IN THE LIST
url = [
...,
...,
...,
(r"/(?P<picture>.*)", handlers.PictureHandler)]
this is why when using GET method return errors concerning picture! hope this will help, and thank you :)
Upvotes: 3