Skip to content

Instantly share code, notes, and snippets.

View 4k45hv3rm4's full-sized avatar
💻
If world were perfect . It Wouldn't be...

Aakash Verma 4k45hv3rm4

💻
If world were perfect . It Wouldn't be...
View GitHub Profile
from .models import Account
from django.shortcuts import render
from django.contrib import messages
from django.contrib.auth import (
authenticate,
logout ,
login
)
from django.shortcuts import (
render,
from django import forms
from .models import Account
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
from django.contrib.auth.forms import UserCreationForm
class RegistrationForm(UserCreationForm):
"""
Form for Registering new users
"""
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
#manager for our custom model
class MyAccountManager(BaseUserManager):
"""
This is a manager for Account class
"""
def create_user(self, email, username, password=None):
if not email:
def home(request):
#rendering our home page
return render(request, 'home.html')
from django.urls import path
from account import views
app_name="account"
urlpatterns=[
path('register/' , views.register , name="register"),
path('user_login/', views.user_login, name="user_login"),
path('home/', views.home, name="home"),
]
"""login_system URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
{% extends "account/base.html" %}
{% block body_block %}
<div class="container">
<div class="jumbotron">
<h1>Welcome to the our Login System !!!</h1>
{% if user.is_authenticated %}
<h2>Hello {{ user.username }}</h2>
{% else %}
<h2>Register or Login if you'd like to</h2>
{% endif %}
{% extends 'account/base.html' %}
{% block body_block %}
<div class="container ">
<div class="">
<h1>Login here :</h1>
<form method="post" action="{% url 'account:user_login' %}">
{% csrf_token %}
<p><label for="username">Username:</label>
<input type="text" name="username" placeholder="Username">
</p>
{% extends "account/base.html" %}
{% load static %}
{% block body_block %}
<div class="container ">
{% if registered %}
<h1>Thank you for registering!</h1>
{% else %}
<h1>Register Here</h1>
<h3>Just fill out the form.</h3>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Base</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>