python - Django中的模型字段验证
问题描述
我想验证一个自定义表单域。我已经制作了联系我们表格的模型。字段是名称、主题、电子邮件和消息。现在“DIU”公司的用户只能联系我们。email 的电子邮件地址中必须包含“35-”和“@diu.edu.bd”。我怎样才能像这样验证这个电子邮件字段?请帮忙
解决方案
在你的模型中这样的东西怎么样:
def clean_email(self):
email = self.cleaned_data['email'].lower()
if '@diu.edu.bd' not in email or '35-' not in email:
raise forms.ValidationError(u'You are not authorized to send us email.')
return email
推荐阅读
- apache-spark - 使用 spark-submi 无法从 hive 中找到表
- php - MySQL 根据日记帐、收据和付款表查询所有帐户的期初余额、借方、贷方和期末余额
- node.js - 在 Axios 中发布包含 cookie 时出现网络错误
- python - 如何从子类中获取抽象类名
- html - 如何在 html 和 css 样式中拉伸背景图像?
- sql - 如何连接oracle11g数据库?
- postgresql - Postgresql 没有连接
- react-native - React Native:双击退出应用程序
- html - 很难解释,模仿这个链接栏悬停效果
- adal.js - ADAL、Angular 6 和保护 MVC API