Create a student registration app using Django

Create student registration app using django

To create a student registration app using Django, you can follow these steps:

Create a new Django project:
Open your terminal and navigate to the directory where you want to create the project. Then, run the following command to create a new Django project:

django-admin startproject registration_app

Create a new Django app:
Next, you need to create a new Django app within your project. In your terminal, navigate to the project directory and run the following command:

python manage.py startapp student_registration

Define the database models:
In your Django app’s models.py file, define the database models for your student registration app. For example, you might have a Student model with fields like name, email, phone number, and date of birth.
scss

from django.db import models

class Student(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField()
phone_number = models.CharField(max_length=20)
date_of_birth = models.DateField()

Create the database tables:
Run the following command in your terminal to create the database tables for your app:

python manage.py makemigrations student_registration
python manage.py migrate

Create the views:
In your Django app’s views.py file, create the views for your student registration app. For example, you might have a view for displaying a form to register a new student, and a view for displaying a list of all registered students.
python

 

from django.shortcuts import render, redirect
from .models import Student
from .forms import StudentForm

def register_student(request):
if request.method == 'POST':
form = StudentForm(request.POST)
if form.is_valid():
form.save()
return redirect('student_list')
else:
form = StudentForm()
return render(request, 'register.html', {'form': form})

def student_list(request):
students = Student.objects.all()
return render(request, 'student_list.html', {'students': students})

Create the templates:
Create HTML templates for your views. For example, you might have a template for the student registration form and a template for displaying a list of registered students.

Define the URLs:
In your Django app’s urls.py file, define the URLs for your views. For example:

from django.urls import path
from . import views

urlpatterns = [
path('register/', views.register_student, name='register_student'),
path('students/', views.student_list, name='student_list'),
]

Add the app to the project:
Finally, you need to add your app to the list of installed apps in your project’s settings.py file:

INSTALLED_APPS = [ ... 'student_registration',]

 

That’s it! Your student registration app is now ready to use. Run the development server with the following command:

python manage.py runserver

Then, navigate to http://localhost:8000/register/ to register a new student, or http://localhost:8000/students/ to see a list of registered students.

Read on django here

Share
Share
Scroll to Top