first register form and got stuck!

74 views
Skip to first unread message

aliane abdelouahab

unread,
Jul 26, 2012, 1:44:32 PM7/26/12
to Tornado Web Server
hi, am a real newbie, and it's my first application, and am stacked!
so here is my problem:
i wanna make a form submission, and here is the html:

from register-entr.html

<form name="reg" id="register" action="register-entr.html"
method="post" enctype="multipart/form-data">
{% raw xsrf_form_html() %}
<input id="pseudo">
<input id="pass1">
<input id="pass2">
<input id="email">
<input id="tel">
<input id="validate" type="submit" value="Confirmer"/>
<form/>

and here is the tornado problem:
from the file handlers.py

class RegistrationE(tornado.web.RequestHandler):
def post(self):
pseudo = self.get_argument("pseudo")
pass1= self.get_argument("pass1")
pass2= self.get_argument("pass2")
email= self.get_argument("email")
tel= self.get_argument("tel")
commune= self.get_argument("commune")
def get(self):
self.render("register-entr.html")

and
from the app.py

urls = [
(r"/", handlers.MainHandler),
(r"/register-entr.html", handlers.RegistrationE)
]

he gives me 405 Method not allowd!

what i want to do is to finalisze the registration -not yet used the
database, just to verify, am going slowly ;)- so when the user
validate the registration it will be redirected to a page where he can
see a new page (where i used langage template like : Hi {{pseudo}},
your phone is {{tel}})

NB: the registration and login are in the same page, i've used a CSS3
Accordion effect :p

Jorge Puente Sarrín

unread,
Jul 26, 2012, 1:46:15 PM7/26/12
to python-...@googlegroups.com
Do have enable xsrf_cookies ?

2012/7/26 aliane abdelouahab <alabde...@gmail.com>



--
Atte.
Jorge Puente Sarrín.

aliane abdelouahab

unread,
Jul 26, 2012, 2:01:09 PM7/26/12
to Tornado Web Server
yes, in the setting of app.py there is a looooooong word used to
verify if it's the same from the request or not (from i understand)

On 26 juil, 18:46, Jorge Puente Sarrín <puentesar...@gmail.com> wrote:
> Do have enable *xsrf_cookies ?*
>
> 2012/7/26 aliane abdelouahab <alabdeloua...@gmail.com>

Jorge Puente Sarrín

unread,
Jul 26, 2012, 2:07:02 PM7/26/12
to python-...@googlegroups.com
Yes, you should to add this line inside at your form:

{% raw xsrf_form_html() %}


Regards.


2012/7/26 aliane abdelouahab <alabde...@gmail.com>

aliane abdelouahab

unread,
Jul 26, 2012, 2:13:00 PM7/26/12
to Tornado Web Server
yes, it's there, and the resulted html, i've checked the source and it
become a form with "hidden" attribute, but from what i've read, error
405 is when there is a problem between GET and POST, so can't i mix
them? :o

On 26 juil, 19:07, Jorge Puente Sarrín <puentesar...@gmail.com> wrote:
> Yes, you should to add this line inside at your form:
>
> {% raw xsrf_form_html() %}
>
> Regards.
>
> 2012/7/26 aliane abdelouahab <alabdeloua...@gmail.com>

Jorge Puente Sarrín

unread,
Jul 26, 2012, 4:59:11 PM7/26/12
to python-...@googlegroups.com
Can you write the traceback?

2012/7/26 aliane abdelouahab <alabde...@gmail.com>

aliane abdelouahab

unread,
Jul 26, 2012, 8:07:37 PM7/26/12
to Tornado Web Server
sorry for the delay
in the console (i use Aptana Studio) there is nothing, the response is
OK, untill i get the bad request :'(
tomorrow i'll copy all the code.

On 26 juil, 21:59, Jorge Puente Sarrín <puentesar...@gmail.com> wrote:
> Can you write the traceback?
>
> 2012/7/26 aliane abdelouahab <alabdeloua...@gmail.com>

aliane abdelouahab

unread,
Jul 26, 2012, 8:08:15 PM7/26/12
to Tornado Web Server
*because am not at home, am in a cyber cafe

On 26 juil, 21:59, Jorge Puente Sarrín <puentesar...@gmail.com> wrote:
> Can you write the traceback?
>
> 2012/7/26 aliane abdelouahab <alabdeloua...@gmail.com>
Message has been deleted
Message has been deleted

Cheng Wei

unread,
Jul 27, 2012, 1:38:03 AM7/27/12
to python-...@googlegroups.com
the error might be ` enctype="multipart/form-data"`, that used for fileupload.   Just remove it

aliane abdelouahab

unread,
Jul 27, 2012, 9:42:33 AM7/27/12
to Tornado Web Server
i'll try it when i'll back home, i've bring the entire code:

here is the register-entr.html

<form id="register" action="register-entr.html" method="post"
enctype="multipart/form-data">
{% raw xsrf_form_html() %}
<div id="enregistrer">
<div class="loginn">
<label for="pseudo">Votre nom</label>
<input id="pseudo" type="text" required placeholder="nom
d'utilisateur" pattern="([a-zA-Z0-9]{3,})+" title="doit contenir
uniquement des lettres ou des chiffres sans espaces par exemple
MouhVendeur45, minimum 3 caract&egrave;res">
<label for="pass1">Votre mot de passe</label>
<input id="pass1" type="password" required
onkeypress="checkCapsLock(event);" placeholder="un mot de passe long"
pattern=".{6,}" title="pour votre securit&eacute;, minimum 6
caract&egrave;res, evitez les dates de naissances ou les choses qu'un
autre pourra deviner">
<label for="pass2">Confirmez le</label>
<input id="pass2" type='password' required
onkeypress="checkCapsLock(event);" placeholder="retappez le mot de
passe" onblur="checkPassword(document.getElementById('pass1'), this);"
title="retappez le mot de passe">
<div id="caps-on-warning" style="visibility: hidden;">Vous avez
activ&eacute; la touche majiscule</div>
<label for="email">Votre email</label>
<input id="email" type="email" required placeholder="votre email">
</div>
</form>

and users.html
<body>
bienvenue {{pseudo}}, votre adresse email est {{email}}
</body>

and here is the handlers.py

class EHandler(tornado.web.RequestHandler):
def get(self):
self.render("register-entr.html")
def post(self):
pseudo = self.get_argument("pseudo", "")
tel = self.get_argument("tel", "")
self.redirect("users.html")

and app.py
urls = [
(r"/", handlers.MainHandler),
(r"/register-entr.html", handlers.EHandler),
(r"/register-pers.html", handlers.IHandler),
(r"/users.html", handlers.UserHandler),

]

settings = dict({
"template_path":
os.path.join(os.path.dirname(__file__),"templates"),
"static_path": os.path.join(os.path.dirname(__file__),"static"),
"cookie_secret": "bZJc2sWbQLKos6GkHn/VB9oXwQt8S0R0kRvJ5/xJ89E=",
"xsrf_cookies": True,
"site_url":"http://localhost:8000"
})

and here is the traceball

[E 120727 14:21:16 template:257] users.html code:
1 def _execute(): # users.html:0
2 _buffer = [] # users.html:0
3 _append = _buffer.append # users.html:0
4 _append('<!DOCTYPE html>\n<!-- ce que c\'est beau les
docyptes de HTML5 -->\n<html lang="fr-FR">\n<head>\n<meta
charset=UTF-8/>\n<!--vous allez remarquer de droles caracteres, c
parceque c le moyen de les afficher sur la page web, consultez sa pour
avoir le tableau http://webdesign.about.com/od/localization/l/blhtmlcodes-fr.htm
-->\n<title>toz</title>\n<link href="../static/css/acc-big.css"
rel="stylesheet" media="screen and (min-device-width: 1360px)">\n</
head>\n<body>\nbienvenue ') # users.html:11
5 _tmp = pseudo # users.html:11
6 if isinstance(_tmp, _string_types): _tmp = _utf8(_tmp) #
users.html:11
7 else: _tmp = _utf8(str(_tmp)) # users.html:11
8 _tmp = _utf8(xhtml_escape(_tmp)) # users.html:11
9 _append(_tmp) # users.html:11
10 _append(', votre adresse email est ') # users.html:11
11 _tmp = email # users.html:11
12 if isinstance(_tmp, _string_types): _tmp = _utf8(_tmp) #
users.html:11
13 else: _tmp = _utf8(str(_tmp)) # users.html:11
14 _tmp = _utf8(xhtml_escape(_tmp)) # users.html:11
15 _append(_tmp) # users.html:11
16 _append('\n</body>\n</html>') # users.html:13
17 return _utf8('').join(_buffer) # users.html:0
[E 120727 14:21:16 web:1064] Uncaught exception GET /users.html (::1)
HTTPRequest(protocol='http', host='localhost:8000', method='GET',
uri='/users.html', version='HTTP/1.1', remote_ip='::1', body='',
headers={'Accept-Language': 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4',
'Accept-Encoding': 'gzip,deflate,sdch', 'Host': 'localhost:8000',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64)
AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/
536.5', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Connection': 'keep-alive', 'Referer': 'http://localhost:8000/register-
entr.html', 'Cache-Control': 'max-age=0', 'Cookie':
'user="ImFiZGVsb3VhaGFiQHlhaG9vLmZyIg==|1343357691|
379b4e3810fc2f228f4b8f884eda68d6fe645faf";
_xsrf=ef4733bf0f704ff5ab3d00f72161af16'})
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\tornado-2.3-py2.7.egg\tornado
\web.py", line 1021, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "G:\Mon projet\sog-emouk\handlers.py", line 41, in get
self.render("users.html")
File "C:\Python27\lib\site-packages\tornado-2.3-py2.7.egg\tornado
\web.py", line 498, in render
html = self.render_string(template_name, **kwargs)
File "C:\Python27\lib\site-packages\tornado-2.3-py2.7.egg\tornado
\web.py", line 615, in render_string
return t.generate(**args)
File "C:\Python27\lib\site-packages\tornado-2.3-py2.7.egg\tornado
\template.py", line 254, in generate
return execute()
File "users_html.generated.py", line 5, in _execute
_tmp = pseudo # users.html:11
NameError: global name 'pseudo' is not defined
[E 120727 14:21:16 web:1447] 500 GET /users.html (::1) 3.00ms

is that an unicode issue (using French) ?

On 27 juil, 06:38, Cheng Wei <willc...@gmail.com> wrote:
> the error might be ` enctype="multipart/form-data"`, that used for
> fileupload.   Just remove it
> More info you can find athttp://stackoverflow.com/questions/4007969/application-x-www-form-url...

Lorenzo Bolla

unread,
Jul 27, 2012, 10:35:14 AM7/27/12
to python-...@googlegroups.com
The problem is probably in your UserHandler, which you haven't pasted.
In particular:

    NameError: global name 'pseudo' is not defined

You are probably playing the template without the necessary parameters.
In UserHandler, you should have a line like:
   self.render('user.html', pseudo=..., email=...)

Moreover, why specifying the extension ".html" in the routing table? I'd just use "/", "/users", "/register".

L.

aliane abdelouahab

unread,
Jul 27, 2012, 10:47:59 AM7/27/12
to Tornado Web Server
ah!!! now i see!!!
i'll go home now, and try it :D
thank you again
and sorry, am a beginner, it's my first application :p

On 27 juil, 15:35, Lorenzo Bolla <lbo...@gmail.com> wrote:
> The problem is probably in your UserHandler, which you haven't pasted.
> In particular:
>
>     NameError: global name 'pseudo' is not defined
>
> You are probably playing the template without the necessary parameters.
> In UserHandler, you should have a line like:
>    self.render('user.html', pseudo=..., email=...)
>
> Moreover, why specifying the extension ".html" in the routing table? I'd
> just use "/", "/users", "/register".
>
> L.
>
> On Fri, Jul 27, 2012 at 2:42 PM, aliane abdelouahab <alabdeloua...@gmail.com

aliane abdelouahab

unread,
Jul 27, 2012, 2:08:13 PM7/27/12
to Tornado Web Server
nope,
sadly nothing worked! always showin the "pseudo" is
unknown!!!!!!!!!!!!!!!! am driving crazy!

aliane abdelouahab

unread,
Jul 28, 2012, 9:29:06 AM7/28/12
to Tornado Web Server
ok; solved at 50%, the problem is that i was using ID and not NAME:
http://www.velocityreviews.com/forums/t158063-whats-the-differences-between-id-and-name-attribute.html
....
but the problem now, is how to send the attribute to another page
(from register page to user page, and i need to verify the register
page!), i've tried:
if self.get_argument('pseudo') == ''
self.write("you baypassed the html5 forms& you're a hacker!")
else:
self.redirect("/users")

but the page users.html will be rendered as a BLANK PAGE!
Reply all
Reply to author
Forward
0 new messages