[Django] View class and Form

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值