当然你也可用另一个:publisher_list,如你所想,publisher是模型的名字,这是Django为你提供的第二选择。如果你仍然觉得这个名字不完美,你也可以自己命名,方法是在通用视图中添加context_object_name变量: 1 2 3 4 5 6 7 # views.py fromdjango.views.genericimportListView frombooks.modelsimportPublisher classPubli...
在django1.3之前视图是基于函数[function-based generic views]的方式来实现的。class-based views是django1.3的重要特性之一.就是使用类的形式来描述view。class-based views更加面向对象;使程序的变得简单清晰,并且易于扩展维护。可以将一些公用的东西抽象出来,供别的类继承使用,减少了大量的重复的单调的冗余的代码编写...
在这个视图中,使用定制的form_class并重写form_valid()来增加user: 1 2 3 4 5 6 7 8 9 10 11 12 # views.py fromdjango.views.generic.editimportCreateView frommyapp.modelsimportAuthor frommyapp.formsimportAuthorForm classAuthorCreate(CreateView): form_class=AuthorForm model=Author defform_valid(...
This index provides an alternate organization of the reference documentation for class-based views. For each view, the effective attributes and methods from the class tree are represented under that view. For the reference documentation organized by the class which defines the behavior, see Class-bas...
Generic display views¶ The two following generic class-based views are designed to display data. On many projects they are typically the most commonly used views. DetailView¶ classdjango.views.generic.detail.DetailView¶ While this view is executing,self.objectwill contain the object that the...
This ticket aims to add more class based views to the generic ones provided by django. I've implemented a FormSetsView, a ModelFormSetsView and a InlineFormSetsView. Related django-dev thread:http://groups.google.com/group/django-developers/browse_thread/thread/6964432300ca0c6f/9aa1f1ea...
1. Generic views通用视图 1.1 通用视图介绍 Django REST framework的Generic views称为通用视图,日常使用较多。基于类的视图的主要优势之一是它们允许您组合可重用的行为。DRF利用了这一点,提供了许多预构建的视图。Generic views通用视图相关类如下: generics模块 ...
https://docs.djangoproject.com/en/3.1/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home ...
Edit Views: CreateView, UpdateView, DeleteView 通用视图简介 通用视图包含的 属性,方法,context Display Views ListView ListView展示一系列对象(用于展示一个 Model 里面的所有对象,也可以是其子集 (queryset) ),支持分页 fromdjango.views.genericimportListViewfrombooks.modelsimportPublisherclassPublisherList(ListView...
only the View class deals with the fundamental interaction of python classes with the Django request/response flow and infrastructure - while the other classes are just "one way of doing it" even thought those in base.py are pretty hard to argue with.comment...