472,993 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

problems occured in Login function(Django)


i have small problems occurred in my login function, which i use Django to build,
in my template which is login.html, the code is like the following:

Expand|Select|Wrap|Line Numbers
  2. <html>
  3. <head>
  4. <title>Login</title>
  5. <link rel="stylesheet" type="text/css" href= "/HNV_css/hnv.css" >
  6. <script src="menuscript.js" type="text/javascript"></script>
  7. <script type="text/javascript">
  8. <!-- Begin
  9. function testLogIn(form) {
  10.     var validTxt = true;
  11.     if(document.memLogIn.username.value ==""){
  12.         validTxt = false;
  13.         alert("Please type in the user name");
  14.     }
  15.     else if (document.memLogIn.password.value == "") {
  16.         validTxt = false;
  17.         alert("Please type in the password")
  18.     }
  20.     return validText;
  22. }
  24. // End -->
  25. </script>
  26. </head>
  28. <body>
  29. <center><font face="Arial">
  30.         <h1>Login</h1></font></div>
  33.     {% if form.has_errors %}
  34.         <p>Sorry, that's not a valid username or password</p>
  35.     {% else %}
  37.     {% endif %}
  39.     <form action = "" method = "POST" name="memLogIn" onSubmit="return testLogIn(this)">
  41.     <table border =0>
  42.     <tr><td><label for="id_username"> Name: </td><td> {{ form.username }} </td></tr>
  43.     <tr><td><label for="id_password"> Password: </td> <td> {{ form.password }} </td></tr>
  44.     </table>
  46.     <input type="submit" value="login" />
  47.     <input type="hidden" name="next" value="{{ next }}" />
  49.     </form>
  51. </center>
  53. </body>
  54. </html>
in my views.py , the code is in the following:
Expand|Select|Wrap|Line Numbers
  2. def my_view(request):
  3.     username = request.POST['username']
  4.     password = request.POST['password']
  5.     user = authenticate(username=username, password=password)
  6.     if user is not None:
  7.         if user.is_active:
  8.             login(request, user)
  9.             return HttpResponseRedirect("/carbooking/")
  11.         else:
  12.         return render_to_response('login_error.html')
  14.     else:
  15.         # Return an 'invalid login' error message.
  16.          return render_to_response('login_error.html')
i am not very sure where is wrong, but the error message always told me that

Request URL: http://localhost:8000/accounts/login/
Exception Type: MultiValueDictKeyError
Exception Value: "Key 'username' not found in <MultiValueDict: {}>"
Exception Location: c:\python25\lib\site-packages\django\utils\datastructures.py in __getitem__, line 136

i am quite new to Django framework, i did not really total understand what this error means, can anyone help me with this.. really thanks for any kind of help :)
Nov 5 '07 #1
0 1286

Sign in to post your reply or Sign up for a free account.

Similar topics

by: eric.moritz | last post by:
One of the most respected and award-winning newspaper Web teams in the world has moved to Florida and is looking for an experienced server-side Web developer. NDN Productions -- the online and...
by: Skink | last post by:
Hi, I'm relatively new to django and maybe my question is stupid, but... Is it possible to map in urls.py some url not to function in views.py (which has first argument with HttpRequest) but...
by: Antal Rutz | last post by:
hi, is there something wrong with django's website (djangoproject.com) or I have problems? It looks ugly, the css files can't be found, I even cannot download the source from there. Do you...
by: guile | last post by:
hi, i'm running apache 2.2.3 on windows xp and have python 2.5 and mysql 5 installed. i'm having problems installing django. please give me some help. i created a folder "django" in my...
by: kang jia | last post by:
hi i am very new to python, and my final year project requires me to use Django framework to do application. Although now i understand their logic and some simple application exercise, yet how...
by: kang jia | last post by:
hi guys i am very new to python and Django framework and currently i am doing my final year project by using this language. currently i understand their basic logic, however, i did not really know...
by: kang jia | last post by:
hi i am currently learning Django framework and i have to do a login page at the moment. i have used the code like following: from django.contrib.auth import authenticate, login def...
by: kang jia | last post by:
hi currently, i am using Django to create webpage, in view.py the code is in the following: def contact(request): if request.method == 'POST': form =...
by: circularfunc | last post by:
i have been trying to get Django running for 2 days now and it drives me crazy. i played with webpy a bit and it is easy to get going with. but django seems like once you have it all up and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.