class django.views.generic.base.TemplateView
Renders a given template, with the context containing parameters captured in the URL.
Ancestors (MRO)
This view inherits methods and attributes from the following views:
django.views.generic.base.TemplateResponseMixin
django.views.generic.base.ContextMixin
django.views.generic.base.View
Method Flowchart
dispatch()
http_method_not_allowed()
get_context_data()
Example views.py:
1 2 3 4 5 6 7 8 9 10 11 12 | from django.views.generic.base import TemplateView from articles.models import Article class HomePageView(TemplateView): template_name = "home.html" def get_context_data( self , * * kwargs): context = super (HomePageView, self ).get_context_data( * * kwargs) context[ 'latest_articles' ] = Article.objects. all ()[: 5 ] return context |
Example urls.py:
1 2 3 4 5 6 7 | from django.conf.urls import url from myapp.views import HomePageView urlpatterns = [ url(r '^$' , HomePageView.as_view(), name = 'home' ), ] |
Context
- Populated (through
ContextMixin
) with the keyword arguments captured from the URL pattern that served the view.
Please login to continue.