-
在執行此視圖時,
self.object
將包含視圖正在操作的對象。祖先 (MRO)
此視圖從以下視圖繼承方法和屬性:
django.views.generic.detail.SingleObjectTemplateResponseMixin
django.views.generic.base.TemplateResponseMixin
django.views.generic.detail.BaseDetailView
django.views.generic.detail.SingleObjectMixin
- View
方法流程圖
setup()
dispatch()
http_method_not_allowed()
get_template_names()
get_slug_field()
get_queryset()
get_object()
get_context_object_name()
get_context_data()
get()
render_to_response()
示例 myapp/views.py:
from django.utils import timezone from django.views.generic.detail import DetailView from articles.models import Article class ArticleDetailView(DetailView): model = Article def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['now'] = timezone.now() return context
示例 myapp/urls.py:
from django.urls import path from article.views import ArticleDetailView urlpatterns = [ path('<slug:slug>/', ArticleDetailView.as_view(), name='article-detail'), ]
示例 myapp/article_detail.html:
<h1>{{ object.headline }}</h1> <p>{{ object.content }}</p> <p>Reporter: {{ object.reporter }}</p> <p>Published: {{ object.pub_date|date }}</p> <p>Date: {{ now|date }}</p>
本文介紹 django.views.generic.detail.DetailView
的用法。
聲明
class django.views.generic.detail.DetailView
相關用法
- Python Decimal shift()用法及代碼示例
- Python Decimal rotate()用法及代碼示例
- Python Decimal max_mag()用法及代碼示例
- Python Decimal as_integer_ratio()用法及代碼示例
- Python Decimal is_subnormal()用法及代碼示例
- Python Decimal canonical()用法及代碼示例
- Python Decimal from_float()用法及代碼示例
- Python Decimal normalize()用法及代碼示例
- Python Decimal radix()用法及代碼示例
- Python Decimal copy_abs()用法及代碼示例
- Python Decimal is_finite()用法及代碼示例
- Python Decimal conjugate()用法及代碼示例
- Python Decimal min_mag()用法及代碼示例
- Python Decimal logical_invert()用法及代碼示例
- Python Decimal next_plus()用法及代碼示例
- Python Decimal轉String用法及代碼示例
- Python Decimal compare_total_mag()用法及代碼示例
- Python Decimal is_snan()用法及代碼示例
- Python Decimal to_integral_value()用法及代碼示例
- Python MongoDB Delete_one()用法及代碼示例
- Python Django DeleteView.template_name_suffix用法及代碼示例
- Python Decimal next_toward()用法及代碼示例
- Python Decimal as_tuple()用法及代碼示例
- Python Decimal max()用法及代碼示例
- Python Decimal scaleb()用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.views.generic.detail.DetailView。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。