这篇文章将为大家详细讲解有关Django中有哪些视图类型,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。1、基于功能的视图基于函数的视图是使用python中的函数编写的,该函数以HttpReq
这篇文章将为大家详细讲解有关Django中有哪些视图类型,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
1、基于功能的视图
基于函数的视图是使用python中的函数编写的,该函数以HttpRequest对象作为参数并返回HttpResponse对象。基于功能的视图通常分为4种基本策略,即CRUD(创建,检索,更新,删除)。CRUD是用于开发的任何框架的基础。
# import the standard DjanGo Model# from built-in libraryfrom django.db import models # declare a new model with a name "GeeksModel"class GeeksModel(models.Model): # fields of the model title = models.CharField(max_length = 200) description = models.TextField() # renames the instances of the model # with their title name def __str__(self): return self.title
2、基于类的视图
基于类的视图提供了一种将视图实现为Python对象而非函数的替代方法。与基于函数的视图相比,基于类的视图更易于管理。
from django.views.generic.list import ListViewfrom .models import GeeksModel class GeeksList(ListView): # specify the model for list viewmodel = GeeksModel
关于Django中有哪些视图类型就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
--结束END--
本文标题: Django中有哪些视图类型
本文链接: https://www.lsjlt.com/news/272727.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0