Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Login and Registration Forms with Contrib.Auth in Django

Tags:

forms

django

I'm new to Django and in bouncing around the framework over the past few days I haven't been able to figure out how to properly install the django.contrib.auth app in my project. Well, installing is probably not the right word, but configuring it for my purposes.

What I'm truly hoping to do is extend the built-in classes to simply create registration and login forms, since my User class is working just fine from terminal.

In settings.py I have django.contrib.auth in my INSTALLED_APPS. I also have installed the Authentication Middleware and Sessions Middleware.

I can also clearly see in Django.contrib.auth.views and Django.contrib.auth.forms where the registration and authentication handlers are.

My problem, it seems, since I'm new to the framework, is properly including these files in my project and generating the HTML forms for registration and login.

(As in, do I need to include these Auth files in my app's forms.py? What do I need to model that hasn't already been modeled for me? And finally, since I can see in Django.contrib.auth.views a need for a registration directory with HTML templates, how can I get these all communicating with each other properly?)

Figured out the problem. Just needed to follow Django's URL Conf conventions. Example: (r'^accounts/login/$', 'django.contrib.auth.views.login'),

like image 239
btw Avatar asked Nov 20 '08 18:11

btw


People also ask

How do you use contrib Auth form in Django?

from django.contrib.auth import authenticate, login def my_view(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) # Redirect to a success page. ... else: # Return an 'invalid ...

What is form Is_valid () in Django?

The is_valid() method is used to perform validation for each field of the form, it is defined in Django Form class. It returns True if data is valid and place all data into a cleaned_data attribute.

What is Django contrib Auth models?

This is the default authentication backend used by Django. It authenticates using credentials consisting of a user identifier and password. For Django's default user model, the user identifier is the username, for custom user models it is the field specified by USERNAME_FIELD (see Customizing Users and authentication).


1 Answers

James Bennet's django-registration is an excellent helper application used for a common registration / login pattern.

like image 52
prairiedogg Avatar answered Oct 21 '22 01:10

prairiedogg