views.py:
Code: Select all
from django.shortcuts import render
from django.views.generic import TemplateView
# Create your views here.
def home_page_view(request):
context = {
"inventory_list": ["Widget 1", "Widget 2", "Widget 3"],
"greeting": "THanK yOu foR viSitiNG!",
}
return render(request, "home.html", context)
class AboutPageView(TemplateView):
template_name = "about.html"
def get_context_data(self, **kwargs): # new
context = super().get_context_data(**kwargs)
context["contact_address"] = "123 Jones Street"
context["phone_number"] = "01234 678910"
return context
< /code>
about.html (die Vorlage): < /p>
Company About Page
The company address is {{contact_address}}.
The company phone number is {{phone_number}}.
< /code>
urls.py:
from django.urls import path
from .views import home_page_view, AboutPageView
urlpatterns = [
path("about/", AboutPageView.as_view()),
path("", home_page_view)
]