Complex Dashboard

 

Creating a home page for a Django project after installing Django involves a few steps, including setting up the project, creating a view for the home page, and adding buttons for "Admin" and "Enter Student ID." Below is a guide on how to achieve this.

 

Prerequisites

Django installed.

A Django project set up.

 

Step 1: Create a Django Project (if not already created)

If you haven’t created a Django project yet, you can do so using the following commands:

django-admin startproject identification_system

cd identification_system

 

Step 2: Create a Django App

Create an app within your project to handle the logic related to the identification system:

python manage.py startapp identification

 

code

python manage.py startapp identification

 

Step 3: Add the App to settings.py

In your settings.py file, add the newly created app to the INSTALLED_APPS list:

 

code

INSTALLED_APPS = [

    ...

    'identification',

]

 

Step 4: Create the Home Page View

In the views.py file of your identification app, create a view for the home page:

 

Code

 

# identification/views.py

from django.shortcuts import render

 

def home(request):

    return render(request, 'home.html')

Step 5: Create the Home Page Template

Create a template folder inside your app directory and then create the home.html file:

 

Code

mkdir identification/templates

touch identification/templates/home.html

Edit the home.html file to include the buttons for "Admin" and "Enter Student ID":

 

html

Copy code

<!DOCTYPE html>

<html>

<head>

    <title>Identification System</title>

</head>

<body>

    <h1>Welcome to the Identification System</h1>

    <button onclick="location.href='/admin/'">Admin</button>

    <button onclick="location.href='/enter-student-id/'">Enter Student ID</button>

</body>

</html>

 

Step 6: Configure URL Routing

Next, set up your URL routing so that the home page can be accessed. Edit the urls.py file in the identification_system project folder:

 

code

# identification_system/urls.py

from django.contrib import admin

from django.urls import path

from identification.views import home

 

urlpatterns = [

    path('admin/', admin.site.urls),

    path('', home, name='home'),

    path('enter-student-id/', enter_student_id, name='enter_student_id'),  # This will be created later

]

 

Step 7: Create the View for "Enter Student ID" (Optional)

If you want to create a view for entering the student ID, you can add it in views.py:

 

code

# identification/views.py

from django.shortcuts import render

 

def home(request):

    return render(request, 'home.html')

 

def enter_student_id(request):

    if request.method == 'POST':

        student_id = request.POST.get('student_id')

        # Handle the student ID here (e.g., validate, search in DB)

    return render(request, 'enter_student_id.html')

Step 8: Create the enter_student_id.html Template (Optional)

Create the enter_student_id.html template to handle student ID input:

 

html

Copy code

<!DOCTYPE html>

<html>

<head>

    <title>Enter Student ID</title>

</head>

<body>

    <h1>Enter Student ID</h1>

    <form method="post">

        {% csrf_token %}

        <input type="text" name="student_id" placeholder="Enter your Student ID">

        <button type="submit">Submit</button>

    </form>

</body>

</html>

 

Step 9: Run the Server

Finally, run the Django development server to see your home page:

 

code

python manage.py runserver

 

Step 10: Access the Home Page

Open your browser and go to http://127.0.0.1:8000/ to see your home page with the buttons for "Admin" and "Enter Student ID."

 

 

Post a Comment

Previous Post Next Post

Contact Form