Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6537059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:34:17+00:00 2026-05-25T10:34:17+00:00

I am trying to implement a registration and login system for my django app

  • 0

I am trying to implement a registration and login system for my django app using django-registration, django-registration-defaults, and django-email-usernames.

Everything installed just fine. django-email-usernames provides a custom login form which allows an email to be used as the username. Here is the code for the form.

from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import authenticate

...

class EmailLoginForm(forms.Form):
    email = forms.CharField(label=_(u"Email"), max_length=75, widget=forms.TextInput(attrs=dict(maxlength=75)))
    password = forms.CharField(label=_(u"Password"), widget=forms.PasswordInput)

    def clean(self):
        # Try to authenticate the user
        if self.cleaned_data.get('email') and self.cleaned_data.get('password'):
            user = authenticate(username=self.cleaned_data['email'], password=self.cleaned_data['password'])
            if user is not None:
                if user.is_active:
                    self.user = user # So the login view can access it
                else:
                    raise forms.ValidationError(_("This account is inactive."))
            else:
                raise forms.ValidationError(_("Please enter a correct username and password. Note that both fields are case-sensitive."))

        return self.cleaned_data

In the urls.py of the django-registration, there is pattern for the login page. It uses the default django.contrib.auth.views.login view for the login.

So in urls.py I got this:

from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.contrib.auth import views as auth_views
from registration.views import activate
from registration.views import register

from email_usernames.forms import EmailLoginForm

...

url(r'^login/$', auth_views.login, {'template_name': 'registration/login.html', 'authentication_form': EmailLoginForm}, name='auth_login'),

...

The django.contrib.auth.views.login takes in a template_name and form to use. I’m passing those in as you can see above. I’m setting the template and setting the authentication_form to be the one provided by the django-email-usernames.

Then when browse to the login page I get the following error:

TemplateSyntaxError at /accounts/login/
Caught AttributeError while rendering: ‘WSGIRequest’ object has no attribute ‘get’

Template error

In template /Users/Amir/.virtualenvs/scvd/lib/python2.6/site-packages/registration_defaults/templates/registration/login.html, error at line 16
Caught AttributeError while rendering: ‘WSGIRequest’ object has no attribute ‘get’

6   {% endif %}
7   
8   <form method="post" action="{% url django.contrib.auth.views.login %}">{% csrf_token %}
9   <table>
10  <tr>
11      <td>{{ form.username.label_tag }}</td>
12      <td>{{ form.username }}</td>
13  </tr>
14  <tr>
15      <td>{{ form.password.label_tag }}</td>
16      <td>{{ form.password }}</td>
17  </tr>
18  </table>
19  <p><a href="{% url auth_password_reset %}">Forgot</a> your password?  <a href="{% url registration_register %}">Need an account</a>?</p>
20  
21  <input type="submit" value="login" />
22  <input type="hidden" name="next" value="{{ next }}" />
23  </form>
24  
25  {% endblock %}
26  

I’m pretty stuck. I am pretty sure I did urls.py configuration correctly. I don’t understand the erro that is happening with line 16 ({{ form.password }}) in the template.

Please let me know what else I can provide to clarify my question. Thank you so much for your help in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:34:18+00:00Added an answer on May 25, 2026 at 10:34 am

    Seems that your clean() is not so clear

     user = authenticate(username=self.cleaned_data['email'], password=self.cleaned_data['password'])
    

    there is .get missing

     user = authenticate(username=self.cleaned_data.get['email'], password=self.cleaned_data.get['password'])
    

    it’s good practice to use

     def clean(self):
         x = self.cleaned_data.get("username")
         y = self.cleaned_data.get("password")
    

    then you can use

     user = authenticate(username=x, password=y)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.