-
Notifications
You must be signed in to change notification settings - Fork 4
Add a new page to the project
Carlo Occhiena edited this page Mar 28, 2022
·
3 revisions
- Goes into the
templatesfolder and create a new template. I suggest you to copy one of the existing one in order to keep all the reference tobase.htmlandstatic files. - Customize the template accordingly to your needs. You may want to add links, images, or even forms.
- Create a new function or class in order to render the page in
views.pyfile.
# 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")- Add the url into the application's
url.pyfile:
# 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
]- Save and run