扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
最近在项目上用到了 Django 的自带的 Form 表单,遇到了一些坑,今天给大家出的这篇 Python基础教程 也是做了一个简单的总结,大家可以对号出坑。
Form 基础介绍
首先让我们先来了解下 Django 中 Form 表单的基本用法。Django 中提供了两种 Form 表单类型,一种是 forms.Form ,另外一种是 forms.ModelForm 。很明显,一种是普通的 Form 表单类型,另外一种是和 Model 有关联的表单类型。官方文档中是这样来介绍 ModelForm 的:
If you’re building a database-driven app, chances are you’ll have forms that map closely to Django models. For instance, you might have a BlogComment model, and you want to create a form that lets people submit comments. In this case, it would be redundant to define the field types in your form, because you’ve already defined the fields in your model.
For this reason, Django provides a helper class that lets you create a Form class from a Django model.
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流