Extracting username and password from form in django

Extracting username and password from form in django

By : Yuanlin
Date : November 18 2020, 11:13 AM
Hope that helps The reason you can't get the values out of request object is both inputs have no name attribute. request.POST.get('username', '') tries to get the value of an input with a name attribute of username, which in your case does not exist. So add a name attribute and that should do it for you.
You can further utilize Django's forms module which automatically generates and assigns a name attribute for each field, eventually binding those inputs back to your login form. More on this on the official docs.
code :

Share : facebook icon twitter icon
Forget password page, email/username form and new password form

Forget password page, email/username form and new password form

By : wang.ru.jian
Date : March 29 2020, 07:55 AM
wish help you to fix your issue you may want to edit you script so it does not have any syntax errors.
code :
$keyCheck - mysql_num_rows($keyQuery);
$keyCheck = mysql_num_rows($keyQuery);
Django app login - Can I require user to enter email and password only and then lookup username prior to form validation

Django app login - Can I require user to enter email and password only and then lookup username prior to form validation

By : Loren Mercado
Date : March 29 2020, 07:55 AM
This might help you You can tweak your user model to do this. Have your user model extend AbstractBaseUser with USERNAME_FIELD = 'email'. So now you are using the email as the unique identifier, instead of username. This does not mean you cannot have a username anymore, it just does not need to be unique (but it still can).
Now create a form for your login page that only requires an email and password from the user:
code :
class MyLoginForm(forms.Form):

    email = forms.EmailField(widget=EmailInput(attrs={
        'required': 'required',
        'placeholder': ('Email'),

    password = forms.CharField(widget=forms.PasswordInput(attrs={
        'required': 'required',
        'placeholder': ('Password'),

    error_messages = {
        'invalid_login': ('Please ensure you entered the correct email and password.'),

    def __init__(self, *args, **kwargs):
        self.user_cache = None
        super(MyLoginForm, self).__init__(*args, **kwargs)

    def clean(self):
        email = self.cleaned_data.get('email')
        password = self.cleaned_data.get('password')

        if email and password:
            self.user_cache = authenticate(email=email, password=password)
            if self.user_cache is None:
                raise forms.ValidationError(self.error_messages['invalid_login'])

        return self.cleaned_data

    def get_user(self):
        return self.user_cache
class MyLoginView(DjangoTemplateView):

    template_name = 'my/login.html'

    def dispatch(self, request):
        if request.user.is_authenticated():
            return redirect('some-page')
        return super(MyLoginView, self).dispatch(request)

    def get(self, request):
        return self.render_to_response({
            'form': MyLoginForm()

    def post(self, request):
        form = MyLoginForm(data=request.POST)
        if form.is_valid():
            login(request, form.get_user())
            next = request.POST.get('next', reverse('some-page'))
            return redirect(next)
        return self.render_to_response({
            'form': form,
Extracting Username and Password from raw URL

Extracting Username and Password from raw URL

By : user2035915
Date : March 29 2020, 07:55 AM
it helps some times Several people have suggested you can access the querystring via the Request object's QueryString indexer. That indexer appears in System.Web.HttpRequest, and the object in question is System.Net.HttpWebRequest. They are very different things. The HttpUtility class will parse the parameters out of the querystring for you:
code :
    Uri uri = new Uri("http://bookReport/request.aspx?user=abc&password=password&request=1&option=yes");        
    var qs = HttpUtility.ParseQueryString(uri.Query);
how to get username from login form, when reset password link is clicked django

how to get username from login form, when reset password link is clicked django

By : Chaiwat Arson
Date : March 29 2020, 07:55 AM
Adding a new field along with username and password in django's login form

Adding a new field along with username and password in django's login form

By : scott-ess
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I want to edit the login form provided by django and don't want to build a new one because of the security issues. I have looked at other solutions like How to use another field for logging in with Django Allauth? it's a good example but it assigns email id based on mobile number. However I want to add another field that isn't particularly to authenticate just for input based on which redirection is done. I am quite confused about my approach and whether or not it is possible to do so. Kindly suggest. . , You can do that in your forms.py file by doing this.
code :
class UserLoginForm(forms.Form):
    username = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Username'}))
    password = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control','placeholder':'Password'}))
    yourfield = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','placeholder':'yourfield'}))
    def clean(self, *args, **kwargs):
        username = self.cleaned_data.get("username")
        password = self.cleaned_data.get("password")

        #user_qs = User.objects.filter(username=username)
        #if user_qs.count() == 1:
        #   user = user_qs.first()
        if username and password:
            user = authenticate(username=username, password=password)
            if not user:
                raise forms.ValidationError("This user does not exist")
            if not user.check_password(password):
                raise forms.ValidationError("Incorrect password")
            if not user.is_active:
                raise forms.ValidationError("This user is no longer active")
            return super(UserLoginForm, self).clean(*args, **kwargs)
Related Posts Related Posts :
  • Bootstrap3 - Removed container-fluid
  • Bootstrap framework not responsive for asp.net webform
  • How to align two inner divs inside outer absolute positioned div that has fixed width in which both divs have the same w
  • Div to ignore html tags
  • Prevent caching and stale content with a static web site
  • Is there a way to change the whole document with one selector in CSS?
  • why cant I click om my navigationbar links?
  • Is there a CSS/HTML way to cut multiple shapes out of the top/bottom of a div?
  • css border around multiple links/images
  • 'No data was received in the uploaded file', but file is not empty
  • How input boxes save previous entries
  • AMP carousel direction change
  • Bootstrap multiple carousel not working on thumbnails click
  • Is there a way to put a permanent space into an input field?
  • Html boxes not displaying properly
  • How can I change a variable in Jekyll _config.yml dynamically?
  • How can I prevent DIVs from overlapping a right floated image?
  • Eclipse and .tml files highlighting not working
  • Footer is not in the bottom of the window, (phonegap jquery mobile app for windows mobile)
  • How to put div over another
  • How to use glyphicons in bootstrap 3.0
  • Wordpress page links not working
  • How Do I Use CSS to Set the Color of An ALink?
  • Webpage doesn't scroll smoothly on screen
  • YouTube iframe, browser looks for file locally
  • html displaying inline image
  • Font acting differently on IE and Firefox
  • Encoding and decoding of the character references
  • An Image Button navigate to another site html/css
  • IE8 "Save Target as ..." won't display for block elements
  • Image hover transition for span - CSS
  • How to apply min and max on textarea?
  • How to draw multiple horizontal lines (Notebook Paper effect) using css?
  • Table Printing Issue: Gaps in top and Bottom Border of th Elements
  • grouping elements with div and applying stylesheet for that group
  • Click <div> to expand, then click again to shrink - Its expanding, just not shrinking
  • CSS - How can I center a <script>'s output?
  • Django's template variable gets interpreted as HTML
  • ngx datatable vertical scroll with rowheight set to auto
  • How to make input text border with CSS when it's OnFocus
  • Anyone know of a calendar web widget for my website I could use?
  • How does Bootstrap manage to use fixed positioning for navbar on iOS?
  • Centered text in fully clickable table cell
  • Compare HTML and HTML5
  • steps of creating webpage in bangla
  • css root element margin
  • What is the point of using absolute positioning in CSS?
  • Responsive solution for long URLs (that exceed the device width)
  • Divs don't collapse as they should - media queries
  • QTreeWidgetItem display html
  • Testing html/css image on local from jfiddle
  • long attribute value of HTML
  • Why my svg picture is truncated at the bottom when embedded in html
  • Display CSS: some divs fixed, some flexible (2)
  • How to append href strings with variables in html with PHP?
  • css - Why is there a big white space between text lines?
  • div image position fixed + scroll
  • Hide specific elements from html using css
  • how to align the arrow in menu item?
  • How do I create a trapezoidal button using CSS?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org