Django 官方教程翻译项目
import generic 7. 8. from .models import Choice, Question 9. 10. 11. class IndexView(generic.ListView): 12. template_name = 'polls/index.html' 13. context_object_name = 'latest_question_list' 'polls/results.html' 28. 29. 30. def vote(request, question_id): 31. ... # 像上面一样保存 我们在这里使用两个通用视图: ListView 和 DetailView。这两个视图分别抽象“显示一个对象 列表”和“显示一个特定类型对象的详细信息页面”这两种概念。 每个通用视图需要知道它将作用于哪个模型。 这由 model 属性提供。 这确保results视图和detail 视图在渲染时具有不同的外观,即使它们在后台都是同一个 DetailView。 类似地,ListView 使用一个叫做 “/ _detail.html” 的默认模板; 我们使用 template_name 来告诉 ListView 使用已经存在的 “polls/index.html” 模板。 在之前的教程中,提供模板文件时都带有一个包含 0 码力 | 103 页 | 1.86 MB | 1 年前3Django 1.8.x Documentation
from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def html' def vote(request, question_id): ... # same as above We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects” DetailView behind the scenes. Similarly, the ListView generic view uses a default template called/ _list.html; we use template_name to tell ListView to use our existing "polls/index.html" 0 码力 | 2454 页 | 2.85 MB | 1 年前3Django 3.0.x Documentation
extensions Django’s default logging configuration Pagination The Paginator class Example Paginating a ListView Using Paginator in a view function Security in Django Cross site scripting (XSS) protection Cross from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def question_id): ... # same as above, no changes needed. We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects”0 码力 | 3085 页 | 2.95 MB | 1 年前3Django 4.2.x Documentation
Security implications Configuring logging Pagination The Paginator class Example Paginating a ListView Using Paginator in a view function Security in Django Cross site scripting (XSS) protection Cross from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = "polls/index.html" context_object_name = "latest_question_list" def question_id): ... # same as above, no changes needed. We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects”0 码力 | 3305 页 | 3.16 MB | 1 年前3Django 4.1.x Documentation
Security implications Configuring logging Pagination The Paginator class Example Paginating a ListView Using Paginator in a view function Security in Django Cross site scripting (XSS) protection Cross from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def question_id): ... # same as above, no changes needed. We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects”0 码力 | 3240 页 | 3.13 MB | 1 年前3Django 4.0.x Documentation
Security implications Configuring logging Pagination The Paginator class Example Paginating a ListView Using Paginator in a view function Security in Django Cross site scripting (XSS) protection Cross from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def question_id): ... # same as above, no changes needed. We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects”0 码力 | 3184 页 | 3.14 MB | 1 年前3Django 3.2.x Documentation
extensions Django’s default logging configuration Pagination The Paginator class Example Paginating a ListView Using Paginator in a view function Security in Django Cross site scripting (XSS) protection Cross from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def question_id): ... # same as above, no changes needed. We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects”0 码力 | 3121 页 | 3.08 MB | 1 年前3Django 3.1.x Documentation
extensions Django’s default logging configuration Pagination The Paginator class Example Paginating a ListView Using Paginator in a view function Security in Django Cross site scripting (XSS) protection Cross from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def question_id): ... # same as above, no changes needed. We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects”0 码力 | 3094 页 | 3.03 MB | 1 年前3Django 1.8.x Documentation
from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def get_queryset(self): html' def vote(request, question_id): ... # same as above We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects” DetailView behind the scenes. Similarly, the ListView generic view uses a default template called/ _list. html; we use template_name to tell ListView to use our existing "polls/index.html" 0 码力 | 1685 页 | 6.01 MB | 1 年前3Django 1.11.x Documentation
from django.views import generic from .models import Choice, Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def question_id): ... # same as above, no changes needed. We’re using two generic views here: ListView and DetailView. Respectively, those two views abstract the concepts of “display a list of objects” DetailView behind the scenes. Similarly, the ListView generic view uses a default template called/ _list.html; we use template_name to tell ListView to use our existing "polls/index.html" 0 码力 | 2747 页 | 2.67 MB | 1 年前3
共 46 条
- 1
- 2
- 3
- 4
- 5