[Django] View class and Form
2014-01-08 08:31
260 查看
A view is a callable which takes a request and returns a response. This can be more than just a function, and Django provides an example of some classess wich can be used as views.These allow you to structure your views and reuse code by harnessing inheritance
and mixins.
Django provides base view classes which will suite a wide range of applications. All views inherit from the View class, which handles linking the view in to the URLs, HTTP method dispatching and other simple features. RedirectView is for a simple HTTP redirect
, and TemplateView extends the base class to make it also render a template.
The simplest way to use generic views is to create them directly in your URLConf. If you are only changing a few simple attribiutes on a class-based view, you can simply pass them into the as_view() method. Any arguments passed to as_view() will override attribute
sets on the class.
The second, more powerful way to use generic views is to inherit from an existing view and override attributes or methods in your subclassess to provide new values or methods.
django.form is Django's form-handling library. Whiel it is possible to process form submission just using Django's HTTPReuquest class, using the form library takes care of a number of common form-related tasks.
The library is decoupled from the other Django components, such as the database layer, views and templates. Form classess are created as subclassess of django.forms.Form and make use of a declarative style that you will be familiar with if you have used Django's
database models;
and mixins.
Django provides base view classes which will suite a wide range of applications. All views inherit from the View class, which handles linking the view in to the URLs, HTTP method dispatching and other simple features. RedirectView is for a simple HTTP redirect
, and TemplateView extends the base class to make it also render a template.
The simplest way to use generic views is to create them directly in your URLConf. If you are only changing a few simple attribiutes on a class-based view, you can simply pass them into the as_view() method. Any arguments passed to as_view() will override attribute
sets on the class.
The second, more powerful way to use generic views is to inherit from an existing view and override attributes or methods in your subclassess to provide new values or methods.
django.form is Django's form-handling library. Whiel it is possible to process form submission just using Django's HTTPReuquest class, using the form library takes care of a number of common form-related tasks.
The library is decoupled from the other Django components, such as the database layer, views and templates. Form classess are created as subclassess of django.forms.Form and make use of a declarative style that you will be familiar with if you have used Django's
database models;
相关文章推荐
- Django 中 form 表单如何用 view.py 关联到自定义 html 上
- Django开发运维后台(五):formview结合salt执行命令
- How to access UI controls from a user defined class (CFormView based SDI application)
- 基于 Django1.10 文档的深入学习(24)—— Form and field validation 之 cleaned_data
- django:通用视图-UpdateView更新有参数的form类
- [Android] ViewRoot and View class
- Visual Studio 2012 Class View and Object Browser Icons
- Django FormView, TemplateView简单示例
- Tip/Trick: Implement Copy Function with FormView and SqlDatasource
- Tip/Trick: Implement Copy Function with FormView and SqlDatasource
- [Django] ModelViewSet from rest_framework and Router
- Django CBV(Class-Base View) vs FBV(Function-Base View)
- spring <form:checkboxes> tag and css class
- django的FormView实例一则
- Django ModelForm and Form
- Personal Web Site--Databinding using DataList, FormView, and GridView controls
- Django REST framework-教程06-ViewSets and Routers 原创翻译
- Django学习笔记之Class-Based-View
- ViewState, form fields, labels and Javascript(转)
- WinForm中提示Circular base class dependency involving 'TestEncryption.Form' and 'TestEncryption.Form'