Customizing Your Django Home Page
Let's see how we can add our own content by changing the default home page that we saw when we installed Django.
Step 1
Go to your project folder, activate Virtual Environment and Open Visual studio code in project folder
cd C:\my-django\project1\website1
C:\my-django\project1\venv1\scripts\activate.bat
code .
Step 2
Open a new terminal by selecting the terminal menu in vs code
Step 3
Create an app named 'app1' in your project:-
To create the app, run the following command in terminal
python manage.py startapp app1
Step 4
Open views.py file under app folder (app1) and add a view (method) named 'index'
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World
")
Step 5
Create a python file 'urls.py' in app folder(app1) and add the following code
from django. urls import path
from . import views
urlpatterns=[
path('',views.index,name='index')
]
Step 6
Open 'urls.py' under project folder(website1) and change the code as given below
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('',include("app1.urls")),
path("admin/", admin.site.urls),
]
Step 7
Run the project again and See the change on your home page