Hi:
  I build a website and want to login the admin form by python code. I
have disabled the CSRF in my project  and use urllib2 to post data.
here are my codes:
----------------------------------------------------------------------------------------------------------------
import urllib
import urllib2
import cookielib

cj = cookielib.CookieJar()
url_login ='http://127.0.0.1:8000/admin/'
body =
{'csrfmiddlewaretoken':'f85a33be11bd85108a1030fcce96a5ea','username':'root','password':'mypass','this_is_the_login_form':'1'}
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent','Mozilla/4.0 (compatible; MSIE 7.0;
Windows NT 5.1)')]
urllib2.install_opener(opener)
req=urllib2.Request(url_login,urllib.urlencode(body))
u=urllib2.urlopen(req)
print u.read()
print urllib2.urlopen("http://127.0.0.1:8000/admin/sites/
site/").read()
----------------------------------------------------------------------------------------------------------------

but the codes don't seem to work,here is some part of the response
-----------------------------------------------------------------------------------------------
....
<p class="errornote">Looks like your browser isn&#39;t configured to
accept cookies. Please enable cookies, reload this page, and try
again.</p>

<div id="content-main">
<form action="/admin/" method="post" id="login-form"><div
style='display:none'><input type='hidden' name='csrfmiddlewaretoken'
value='678f0507075332a87211dff43d6f9ee4' /></div>
  <div class="form-row">
    <label for="id_username">Username:</label> <input type="text"
name="username" id="id_username" />
  </div>
  <div class="form-row">
    <label for="id_password">Password:</label> <input type="password"
name="password" id="id_password" />
    <input type="hidden" name="this_is_the_login_form" value="1" />
  </div>
  <div class="submit-row">
    <label>&nbsp;</label><input type="submit" value="Log in" />
  </div>
</form>
....

Could anyone give some suggestion?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to