Django user Registration in Pycharm

Hello friends How are you, This is third post on Django Tutorial in the previous post we have learnt How to create and run a Django Project and How to create an attractive custom Homepage in Django. If you don't know how to create and run Django project then first visit the below links.

Create and Run first project in Django 
Create an attractive custom homepage in Django

Now in this  post "Django user Registration" we will learn to create registration form and we will insert data into database. Here actually i am going to use inbuilt registration form of Django and will insert data using the form and at last we will view the registered data using Superuser.

If you want to understand this through video then watch this video i have explained it step by step live

Now I am going to explain it step by step.

Step 1: Create Registration.html page: First create a Registration.html page inside the templates folder, after creating this page your project screen will look like below screenshot

Django user Registration

Now open this Registration.html file and paste the below HTML code into it.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>{{ msg}}</h1>
<form method="post">
    {{ form }}
    {% csrf_token %}
    <input type="submit" value="Save">
</form>
</body>
</html>

Step 2: Create an anchor tag in Homepage.html : Now open homepage.html page and add an anchor tag for linking registration page with Homepage. You have to add a single line see the below screenshot.

Django user Registration

Step 3: Code for views.py : Now open the views.py and type the following code into it.


from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import render, redirect


def Homepage(request):
    return render(request, 'Homepage.html')

def Registration(request):
    if request.method=='POST':
        form=UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return render(request,"Registration.html",{'form':form,'msg':"Registered Successfully"})
    else:
        form=UserCreationForm()
    return  render(request,"Registration.html",{'form':form})

Step 4: Code for urls.py : Now open the urls.py and add a single line into it.

Django user Registration

Step 5: Run Project : Now click on terminal and then type a command python manage.py runserver and press enter.

Django user Registration

When you will press enter you will get an URL just click on it to get output.

Django user Registration

When you will run the command you will get  a output screen like above , just click on highlighted url to get Output. When you will click on the highlighted url you will get output screen like below.

Django user Registration

Now click on Registration menu to open Registration form. When you will you will get screen like below.
Django user Registration

This is the inbuilt registration form of Django framework. Here you can see there are three fields in which first for Username , second for Password and the last one for Password confirmation. Here there are some rules and regulation for creating password. 

Now fill the above form details with a valid username and password that contains at least 8 character.

Django user Registration
After filling the form with valid username and password click on Save button. When everything will be ok then you will get a message like "Registered Successfully".

Django user Registration
Step 6: View Registered Data : If you want to view the registered data then you first need to create a Superuser. To create a superuser click on terminal and follow the given step below

Django user Registration

Now remember the username and password that you entered during creation of a super user. In my case the username for super user is admin.

Now run the project and then type http://127.0.0.1:8000/admin/ in the URL to open Django Administration Login page. When you will type this URl and press enter then you will get screen like below.
Django user Registration
Her just enter your username and password that you have created and then press enter you will get screen like below.
Django user Registration


This is the admin panel of Django here first you get the username by which you have logged in then click on Users to get the list of registered users. Here in the list of registered data , green tick represents the super user and red cross represents the normal user data.

This is the basic registration in Django using inbuilt registration form of Django. In the upcoming post we will learn how we can customize Django admin panel and How we can use Custom Registration in Django.

I hope now you can  create "Registration in Django". If you have any doubt regarding this post  or you want something more in this post then let me know by comment below i will work on it definitely.
 

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 
 
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

If you like my post then share it with your friends. Thanks😊Happy Coding.

Post a Comment

0 Comments