Skip to content

Add a new page to the project

Carlo Occhiena edited this page Mar 28, 2022 · 3 revisions
  1. Goes into the templates folder and create a new template. I suggest you to copy one of the existing one in order to keep all the reference to base.html and static files.
  2. Customize the template accordingly to your needs. You may want to add links, images, or even forms.
  3. Create a new function or class in order to render the page in views.py file.
# landing_page\one_page\views.py

# simplest way to use a class-based view:

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.generic import TemplateView

class MyNewPage(TemplateView):
    template_name = 'landing_page/my_new_page.html'

# simplest way to use a function-based view:

def my_new_page(request):
    return render(request, "landing_page/my_new_page.html.html")
  1. Add the url into the application's url.py file:
# landing_page\one_page\urls.py

from django.urls import path
from . import views

app_name = 'one_page'

urlpatterns = [
    path('', views.HomePage.as_view(), name='home_page'),
    path('about/', views.AboutPage.as_view(), name='about_page'),
    path('new_page/', views.MyNewPage.as_view(), name='new_page'), # using class-based views
    path('new_page_func/', views.my_new_page(), name='new_page_func') # using function-based views
]
  1. Save and run

Clone this wiki locally