To create a
simple home page for your Django project with buttons for "Admin" and
"Enter Student ID," you can follow these streamlined steps:
1.
Set Up
the Django Project (if not already done)
If
you haven't already set up your Django project, do so with these commands:
Use
this code
django-admin startproject
identification_system
cd identification_system
python manage.py startapp
identification
2.
Create a Simple View for the Home Page
In
your app's views.py file, create a view for the home page:
Use
this code:
# identification/views.py
from django.http import HttpResponse
def home(request):
return HttpResponse("""
<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>
""")
3. Set
Up URL Routing
Add
the URL pattern for your home page in your project's urls.py file:
Use this 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), # Home page
path('enter-student-id/', home),
# Placeholder for Enter Student ID (same view for simplicity)
]
4. Run
the Server
Start
the Django development server:
Use this code
python manage.py runserver
5.
Access the Home Page
Open your web browser and go to
http://127.0.0.1:8000/ to view your simple home page with the buttons.
Summary
Minimal Code: Everything is done in just two files:
views.py for the view and urls.py for routing.
Buttons: The buttons are simply links
embedded in the HTML returned by the HttpResponse.
Simple Setup: No need for templates or complex routing.
This approach is
quick and easy, perfect for getting a basic page up and running.