您的位置:首页 > 编程语言 > Go语言

[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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: