I am trying to build a Recruitment Agency Website following and making adjustments to a tutorial from Code with Stein. I have built the signup.html template, I have coded base.html, models.py, the views.py and the urls.py. However when I try to signup a new user, there is no response. In other words the new user does not reflect in Users in the admin panel. Please help. What am I missing?
Here is my forms.py file
from django import forms # type:ignore
from django.contrib.auth.forms import UserCreationForm # type:ignore
from django.contrib.auth.models import User # type:ignore
class SignupForm(UserCreationForm):
class Meta:
model = User
fields = ("username", "email", "password1", "password2")
username = forms.CharField(
widget=forms.TextInput(
attrs={
"placeholder": "Enter Your username",
"class": "w-full py-4 px-6 rounded-xl",
}
)
)
email = forms.CharField(
widget=forms.EmailInput(
attrs={
"placeholder": "Enter Your Email",
"class": "w-full py-4 px-6 rounded-xl",
}
)
)
password1 = forms.CharField(
widget=forms.PasswordInput(
attrs={
"placeholder": "Enter Your password",
"class": "w-full py-4 px-6 rounded-xl",
}
)
)
password2 = forms.CharField(
widget=forms.PasswordInput(
attrs={
"placeholder": "Enter Your password again",
"class": "w-full py-4 px-6 rounded-xl",
}
)
)
the views.py file
from django.shortcuts import render, redirect # type:ignore
from item.models import Category, Item
from .forms import SignupForm
def index(request):
items = Item.objects.filter(is_sold=False)[0:9]
categories = Category.objects.all()
return render(
request, "core/index.html", {"categories": categories, "items": items}
)
def contact(request):
return render(request, "core/contact.html")
def about(request):
return render(request, "core/about.html")
def signup(request):
if request.method == "POST":
form = SignupForm(request.POST)
if form.is_valid():
form.save()
return redirect("/login/")
else:
form = SignupForm()
return render(request, "core/signup.html", {"form": form})
the signup.html file
{% extends "core/base.html" %}
{% block title %}Sign up{% endblock title %}
{% block content %}
<div class="w-1/2 my-6 p-6 mx-auto bg-gray-100 rounded-xl">
<h1 class="mb-6 text-6xl">Sign up</h1>
<form method="post" action="."></form>
{% csrf_token %}
<div class="mb-3">
<label class="inline-block mb-2">Username</label> <br>
{{ form.username }}
</div>
<div class="mb-3">
<label class="inline-block mb-2">Email</label> <br>
{{ form.email }}
</div>
<div class="mb-3">
<label class="inline-block mb-2">Password</label> <br>
{{ form.password1 }}
</div>
<div class="mb-3">
<label class="inline-block mb-2">Repeat Your Password</label> <br>
{{ form.password2 }}
</div>
{% if form.errors or form.non_field_errors %}
<div class="mb-3 p-6 bg-red-100 rounded-xl">
{% for field in form %}
{{ field.errors }}
{% endfor %}
{{ form.non_field_errors }}
</div>
{% endif %}
<button class="py-4 px-8 text-lg bg-teal-500 hover:bg-teal-700 rounded-xl text-white">Submit to Signup/Register</button>
</div>
{% endblock content %}
and the base.html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<title> {% block title %} {% endblock title %} | Agency</title>
</head>
<body>
<nav class="py-6 x-6 flex justify-between items-center border-b boredr-gray-200""">
<a href="/" class="text-xl font-semibold">Agency Job Portal</a>
<div><a href="#" class="text-lg font-semibold hover:text-gray-500">New Opportunity</a>
<a href="#" class="text-lg font-semibold hover:text-gray-500">Browse</a>
<a href="{% url "core:signup" %}" class="px-6 py-3 text-lg font-semibold bg-teal-500 text-white rounded-xl hover:bg-teal-700">Sign Up</a>
<a href="#" class="px-6 py-3 text-lg font-semibold bg-gray-500 text-white rounded-xl hover:bg-gray-700">Login</a>
</div>
</nav>
<div class="px-6 py-6">
{% block content %}
{% endblock content %}
</div>
<footer class="py-6 px-6 flex justify-between bg-gray-800">
<div class="w-2/3 pr-10">
<h3 class="mb-5 font-semibold text-gray-400">About</h3>
<p class="text-lg text-gray-500">Lorem ipsum
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="w-1/3 px-50">
<h3 class="mb-5 font-semibold text-gray-400">Menu</h3>
<ul class="space-y-2">
<li><a href="{% url 'about' %}" class="text-lg text-teal-500 hover:text-teal-700">About</a></li>
<li><a href="{% url 'contact' %}" class="text-lg text-teal-500 hover:text-teal-700">Contact</a></li>
<li><a href="#" class="text-lg text-teal-500 hover:text-teal-700">Privacy</a></li>
<li><a href="#" class="text-lg text-teal-500 hover:text-teal-700">Terms of Use</a></li>
</ul>
</div>
</footer>
</body>
</html>