473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

create Login function in Django

88 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. from django.contrib.auth import authenticate, login
  2.  
  3. def my_view(request):
  4.     username = request.POST['username']
  5.     password = request.POST['password']
  6.     user = authenticate(username=username, password=password)
  7.     if user is not None:
  8.         if user.is_active:
  9.             login(request, user)
  10.             # Redirect to a success page.
  11.              return HttpResponseRedirect("/carbooking/")
  12.         else:
  13.             # Return a 'disabled account' error message
  14.             return render_to_response('login_error.html')
  15.     else:
  16.         # Return an 'invalid login' error message.
  17.         return render_to_response('login_error.html')
  18.  
but it got error message, it says that

MultiValueDictK eyError at /accounts/login/
"Key 'username' not found in <MultiValueDict : {}>"
Request Method: GET
Request URL: http://localhost:8000/accounts/login/
Exception Type: MultiValueDictK eyError
Exception Value: "Key 'username' not found in <MultiValueDict : {}>"

i did not really understand this error message, what should i do so that i can successfully create login page.

my login.html is like this :
Expand|Select|Wrap|Line Numbers
  1.  
  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.     }
  19.  
  20.     return validText;
  21.  
  22. }
  23.  
  24. // End -->
  25. </script>
  26. </head>
  27.  
  28. <body>
  29. <center><font face="Arial">
  30.         <h1>Login</h1></font></div>
  31.  
  32.  
  33.     {% if form.has_errors %}
  34.         <p>Sorry, that's not a valid username or password</p>
  35.     {% else %}
  36.  
  37.  
  38.  
  39.     {% endif %}
  40.  
  41.  
  42.  
  43.  
  44.     <form action = "" method = "POST" name="memLogIn" onSubmit="return testLogIn(this)">
  45.  
  46.     <table border =0>
  47.  
  48.     <tr><td> Name: </td><td> {{ form.username }} </td></tr>
  49.     <tr><td> Password: </td> <td> {{ form.password }} </td></tr>
  50.     </table>
  51.  
  52.     <input type="submit" value="login" />
  53.     <input type="hidden" name="next" value="{{ next }}" />
  54.  
  55.     </form>
  56.  
  57. </center>
  58.  
  59. </body>
  60. </html>
any one can help me with this? i really appreciate any kind of help :) Thanks.
Oct 21 '07 #1
0 2388

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

Similar topics

28
5462
by: flamesrock | last post by:
Firstly, this topic is NOT intended for trolling or starting any flame wars. I want to know if anyone has experience with these frameworks, and if so, how do they compare? Which one do you prefer? Going back to school in a few days, I simply don't have the time to try both. -thanks
0
1134
by: Sokolov Yura | last post by:
Django Model is wonderfull. But SQLObject more flexible (and powerfull, as i think, and has already more db interfaces). But Django Model is tied with Django, and using Django with another OO mapping is not comfortable. Why do not working together? I can't understand. If you (Django and SQLObject) would, you'll beat everyone else in...
1
2323
by: kernel1983 | last post by:
I look it up in PyPI There are info about Django: Package Score Description Django096 0.96 6 Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. DjangoPaste 0.0 6 Integration of Python Paste and Django TurboDjango 0.95w2 6 Django template for TurboGears, need Django to work
4
6895
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in...
4
1630
by: seb.haase | last post by:
Hi! I was surprised when I did a google-groups search for python, ( http://groups.google.com/groups/search?q=python&qt_s=Search+Groups ) it shows these groups: comp.lang.python with about 11000 users, and second, Django users
0
1316
by: kang jia | last post by:
hi 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: <html> <head> <title>Login</title>
4
4911
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 running it will be easier. just that the barrier of entry is much higher. is django worth it? seems so ridicoulusly hard to get it running. i run...
4
2904
by: K | last post by:
Hello everyone, I understand that urllib and urllib2 serve as really simple page request libraries. I was wondering if there is a library out there that can get the HTTP requests for a given page. Example: URL: http://www.google.com/test.html Something like: urllib.urlopen('http://www.google.com/
1
5933
by: Aspersieman | last post by:
On Wed, 05 Nov 2008 08:35:23 +0200, 3000 billg <billg3000@hos.twgg.org> wrote: Hi Excellent choice :)
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.