Articles → DJANGO → Add new pages in Django project

Add new pages in Django project






Steps of adding new pages













Create a new template




<html>

<head></head>

<body>Welcome to Gyan Sangrah: A one stop shop for people preparing for technical interviews. Gyansangrah is an online resource comprising all the possible questions you may face during your technical interview round. Gyansangrah also provides you with live examples to make concepts easier to understand.</body>

</html>



Create a new function in views.py for about page




def about(request):
  return render(request, "about.html", {})




from django.http
import HttpResponse
from django.shortcuts
import render

# Create your views here.
def home(request):
  return render(request, "FirstTemplate.html", {
    "numbers": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  })

def about(request):
  return render(request, "about.html", {})  



Add an entry in urls.py




""
"MyFirstProject URL Configuration

The `urlpatterns`
list routes URLs to views.For more information please see:
  https: //docs.djangoproject.com/en/2.2/topics/http/urls/
  Examples:
  Function views
1. Add an
import: from my_app
import views
2. Add a URL to urlpatterns: path('', views.home, name = 'home')
Class - based views
1. Add an
import: from other_app.views
import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name = 'home')
Including another URLconf
1. Import the include()
function: from django.urls
import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""
"
from django.contrib
import admin
from django.urls
import path
from TestModule.views
import home
from TestModule.views
import about

urlpatterns = [
  path('admin/', admin.site.urls),
  path('', home),
  path('about/', about),

]



Output




Picture showing the new about page in Django

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, June 18, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250