문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| python:django:class-based [2021/11/03 15:43] – [TemplateView] taekgu | python:django:class-based [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | ====== Built-in class-based views API ====== | ||
| + | https:// | ||
| + | * Base views | ||
| + | * View | ||
| + | * TemplateView | ||
| + | * RedirectView | ||
| + | * Generic display views | ||
| + | * DetailView | ||
| + | * ListView | ||
| + | * Generic editing views | ||
| + | * FormView | ||
| + | * CreateView | ||
| + | * UpdateView | ||
| + | * DeleteView | ||
| + | * Generic date views | ||
| + | * ArchiveIndexView | ||
| + | * YearArchiveView | ||
| + | * MonthArchiveView | ||
| + | * WeekArchiveView | ||
| + | * DayArchiveView | ||
| + | * TodayArchiveView | ||
| + | * DateDetailView | ||
| + | * Class-based views mixins | ||
| + | * Simple mixins | ||
| + | * ContextMixin | ||
| + | * TemplateResponseMixin | ||
| + | * Single object mixins | ||
| + | * SingleObjectMixin | ||
| + | * SingleObjectTemplateResponseMixin | ||
| + | * Multiple object mixins | ||
| + | * MultipleObjectMixin | ||
| + | * MultipleObjectTemplateResponseMixin | ||
| + | * Editing mixins | ||
| + | * FormMixin | ||
| + | * ModelFormMixin | ||
| + | * ProcessFormMixin | ||
| + | * DeletionMixin | ||
| + | * Date-based mixins | ||
| + | * YearMixin | ||
| + | * MonthMixin | ||
| + | * DayMixin | ||
| + | * WeekMixin | ||
| + | * DateMixin | ||
| + | * BaseDeteListMixin | ||
| + | * Class-based generic views - flattened index | ||
| + | * Simple generic views | ||
| + | * View | ||
| + | * Template View | ||
| + | * Redirect View | ||
| + | * Detail Views | ||
| + | * DetailView | ||
| + | * List Views | ||
| + | * ListView | ||
| + | * Editing views | ||
| + | * FormView | ||
| + | * CreateView | ||
| + | * UpdateView | ||
| + | * DeleteView | ||
| + | * Date-based views | ||
| + | * ArchiveIndexView | ||
| + | * YearArchiveView | ||
| + | * MonthArchiveView | ||
| + | * WeekArchiveView | ||
| + | * DayArchiveView | ||
| + | * TodayArchiveView | ||
| + | * DateDetailView | ||
| + | |||
| + | ===== class-based의 메소드 호출 ===== | ||
| + | ==== View ==== | ||
| + | ^ 순서 ^ 메소드 ^ 설명 ^ | ||
| + | | 1 | setup(request, | ||
| + | | 2 | dispatch(request, | ||
| + | 기본 구현은 HTTP 메서드를 검사하고 HTTP 메서드와 일치하는 메서드에 위임을 시도합니다; | ||
| + | 기본적으로 HEAD요청은 get()에 위임됩니다. HEAD와 다른 방식으로 요청 을 처리해야 하는 경우, **head()**메서드를 GET재정의할 수 있습니다. </ | ||
| + | | 3 | http_method_not_allowed(request, | ||
| + | |||
| + | 기본 구현은 HttpResponseNotAllowed일반 텍스트로 된 허용된 메서드 목록과 함께 반환 됩니다.</ | ||
| + | | 4 | options(request, | ||
| + | ==== TemplateView ==== | ||
| + | **Method Flowchart** | ||
| + | - setup() | ||
| + | - dispatch() | ||
| + | - http_method_not_allowed() | ||
| + | - get_context_data() | ||
| + | * get_context_data(%%**%%kwargs) - 템플릿 컨텍스트를 나타내는 사전을 반환합니다. 제공된 키워드 인수는 반환된 컨텍스트를 구성합니다. | ||
| + | <code python> | ||
| + | from django.views.generic.base import TemplateView | ||
| + | |||
| + | from articles.models import Article | ||
| + | |||
| + | class HomePageView(TemplateView): | ||
| + | |||
| + | template_name = " | ||
| + | |||
| + | def get_context_data(self, | ||
| + | context = super().get_context_data(**kwargs) | ||
| + | context[' | ||
| + | return context | ||
| + | </ | ||
| + | 적절한 경우 **alters_data** 를 사용하십시오. | ||
| + | |||
| + | 템플릿 컨텍스트에 뷰 인스턴스가 있으면 잠재적으로 위험한 방법을 템플릿 작성자에게 노출시킬 수 있습니다. 이와 같은 메소드가 템플리트에서 호출되지 않도록하려면 해당 메소드에서 alters_data=True 를 설정 하십시오. 자세한 내용 은 템플릿 컨텍스트 렌더링에 대한 설명서를 참조하십시오. | ||
| + | |||
| + | ==== RedirectView ==== | ||
| + | |||
| + | **Method Flowchart** | ||
| + | - setup() | ||
| + | - dispatch() | ||
| + | - http_method_not_allowed() | ||
| + | - get_redirect_url() | ||
| + | * get_redirect_url(*args, | ||
| + | |||