Module apps.registration.views

Expand source code
from django.shortcuts import render
from .forms import RegistrationForm
from django.views import View
from django.views.generic.edit import FormView
from django.urls import reverse_lazy

# Create your views here.
"""
This module will define views for Registration app
"""


class HomeView(View):
    """
    This class will define the home view
    """
    template_name = "registration/home.html"

    def get(self, request, *args, **kwargs):
        """
        This method will render the home page
        Arguments:
            request {object} -- Request object
        Returns:
            object -- HttpResponse object
        """
        context = {}
        return render(request, self.template_name, context)


class UserRegistrationView(FormView):
    """
    This class will define the user registration view
    """
    template_name = "registration/user_registration.html"
    form_class = RegistrationForm
    success_url = reverse_lazy(viewname="registration:login")

    def form_valid(self, form):
        """
        This method will save the form and redirect to login page
        Arguments:
            form {object} -- Form object
        Returns:
            object -- HttpResponse object
        """
        form.save()
        return super().form_valid(form)

Classes

class HomeView (**kwargs)

This class will define the home view

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

Expand source code
class HomeView(View):
    """
    This class will define the home view
    """
    template_name = "registration/home.html"

    def get(self, request, *args, **kwargs):
        """
        This method will render the home page
        Arguments:
            request {object} -- Request object
        Returns:
            object -- HttpResponse object
        """
        context = {}
        return render(request, self.template_name, context)

Ancestors

  • django.views.generic.base.View

Class variables

var template_name

Methods

def get(self, request, *args, **kwargs)

This method will render the home page

Arguments

request {object} – Request object

Returns

object – HttpResponse object

Expand source code
def get(self, request, *args, **kwargs):
    """
    This method will render the home page
    Arguments:
        request {object} -- Request object
    Returns:
        object -- HttpResponse object
    """
    context = {}
    return render(request, self.template_name, context)
class UserRegistrationView (**kwargs)

This class will define the user registration view

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

Expand source code
class UserRegistrationView(FormView):
    """
    This class will define the user registration view
    """
    template_name = "registration/user_registration.html"
    form_class = RegistrationForm
    success_url = reverse_lazy(viewname="registration:login")

    def form_valid(self, form):
        """
        This method will save the form and redirect to login page
        Arguments:
            form {object} -- Form object
        Returns:
            object -- HttpResponse object
        """
        form.save()
        return super().form_valid(form)

Ancestors

  • django.views.generic.edit.FormView
  • django.views.generic.base.TemplateResponseMixin
  • django.views.generic.edit.BaseFormView
  • django.views.generic.edit.FormMixin
  • django.views.generic.base.ContextMixin
  • django.views.generic.edit.ProcessFormView
  • django.views.generic.base.View

Class variables

var form_class

This class will create a form for registration

var success_url
var template_name

Methods

def form_valid(self, form)

This method will save the form and redirect to login page

Arguments

form {object} – Form object

Returns

object – HttpResponse object

Expand source code
def form_valid(self, form):
    """
    This method will save the form and redirect to login page
    Arguments:
        form {object} -- Form object
    Returns:
        object -- HttpResponse object
    """
    form.save()
    return super().form_valid(form)