2018-10-03-Python全栈开发-day60-django序列化-part3

联合唯一

clean_字段方法只能对某个字段进行检查,当clean方法执行完之后,最后还会执行clean方法,在clean方法中,可以通过获取数据字典中的值然后进行验证

  

from django.shortcuts import render,HttpResponsefrom django import formsfrom django.forms import fields# Create your views here.
#联合唯一class Form1(forms.Form):username=fields.CharField(max_length=32)email =fields.CharField(max_length=32)def clean_username(self):print('this is clean_')return self.cleaned_data['username']def clean(self):value_dict=self.cleaned_datausername=value_dict.get('username')email=value_dict.get('email')if username=='ye' and email=='hai':print('this is clean')return value_dict
def index(request):if request.method=='GET':obj=Form1()return render(request,'index.html',{'obj':obj})if request.method=='POST':obj=Form1(request.POST)if obj.is_valid():print('hahah')return HttpResponse('提交成功')else:return render(request,'index.html',{'obj':obj})
view
from django.db import models# Create your models here.class UserInfo(models.Model):username = models.CharField(max_length=32)email = models.EmailField(max_length=32)
models
"""untitled URL ConfigurationThe `urlpatterns` list routes URLs to views. For more information please see:https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views1. Add an import:  from my_app import views2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views1. Add an import:  from other_app.views import Home2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf1. Import the include() function: from django.urls import include, path2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,re_path
from app01 import views
urlpatterns = [path('admin/', admin.site.urls),re_path(r'index',views.index)
]
urls
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<form action="/index" method="post">{{ obj.username }}{{ obj.email }}<input type="submit" value="提交">
</form>
</body>
</html>
templates

 

转载于:https://www.cnblogs.com/hai125698/p/9739752.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/279250.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mac按文件名查找文件_如何在Mac上查找和删除大文件

mac按文件名查找文件Freeing up disk space on a full hard drive can be difficult, especially when it’s full of small files. However, there are some excellent tools for macOS that let you find the files taking up the most space and delete the ones you don’t…

dmg是什么文件格式_什么是DMG文件(以及我该如何使用)?

dmg是什么文件格式DMG files are containers for apps in macOS. You open them, drag the app to your Applications folder, and then eject them, saving you the hassle of the dreaded “Install Wizard” of most Windows apps. So if all they are is a folder for an a…

mysql索引三个字段查询两个字段_mysql中关于关联索引的问题——对a,b,c三个字段建立联合索引,那么查询时使用其中的2个作为查询条件,是否还会走索引?...

情况描述&#xff1a;在MySQL的user表中&#xff0c;对a,b,c三个字段建立联合索引&#xff0c;那么查询时使用其中的2个作为查询条件&#xff0c;是否还会走索引&#xff1f;根据查询字段的位置不同来决定&#xff0c;如查询a, a,b a,b,c a,c 都可以走索引的&#…

canon相机api中文_您应该在佳能相机上掌握的10种相机设置

canon相机api中文Your camera is a tool, and you should be able to use it with total confidence. You should never have to dig through the manual or play around with random buttons trying to work out how to do something on a shoot. Here are the most important…

spring-boot基础概念与简单应用

1.spring家族 2.应用开发模式 2.1单体式应用 2.2微服务架构 微服务架构中每个服务都可以有自己的数据库 3.微服务架构应当注意的细节 3.1关于"持续集成,持续交付,持续部署" 频繁部署、快速交付以及开发测试流程自动化都将成为未来软件工程的重要组成部分 可行方案(如…

邮箱客户端 gmail支持_如何联系Gmail支持

邮箱客户端 gmail支持Although you may not be able to directly contact Gmail support without subscribing to G Suite for businesses, there are a couple of ways to get the answers you’re looking for online. Let’s look at how you can get help with your Gmail …

jstorm mysql_zookeeper,kafka,jstorm,memcached,mysql流式数据处理平台部署

一&#xff0e;平台环境介绍:1&#xff0e;系统信息&#xff1a;项目信息系统版本:Ubuntu14.04.2 LTS \n \l用户&#xff1a;*****密码&#xff1a;******Java环境&#xff1a;openjdk-7-jre语言&#xff1a;en_US.UTF-8&#xff0c;en_US:en磁盘&#xff1a;每台vda为系统盘(5…

dock模拟macos教程_将macOS首选项窗格添加到您的Dock中以快速访问

dock模拟macos教程macOS: Is there a certain Preference pane you access constantly? You can quickly add it to your dock. macOS&#xff1a;是否存在您经常访问的特定“首选项”窗格&#xff1f; 您可以将其快速添加到扩展坞中。 Brett Terpstra, writing for Lifehacke…

怎么做mysql查询系统_mysql数据库系统学习(一)---一条SQL查询语句是如何执行的?...

一、第一节&#xff1a;一条sql查询语句是怎样执行的5.5.5版本以后&#xff0c;默认使用存储引擎为InnoDB不使用查询缓存&#xff0c;MySQL8.0没有查询缓存这个功能总体来说&#xff1a;MySQL分为service层和存储引擎层1)service层包括&#xff1a;连接器、分析器、优化器、执行…

mysql qt自增_mysql自增设置

MySQL设置自增字段的相关语句&#xff1a;alter table album change ALBUM_ID ALBUM_ID bigint not null auto_increment;alter table album auto_increment1;创建:mysql>create table cc(id int auto_increment,name varchar(20),primary key(id));mysql>create table c…

staem被盗_如何检查照片是否被盗

staem被盗Photos and other images get stolen all the time online. Someone takes a photo from the photographer’s website or social media channels and uses it for their own needs. This is completely illegal and happens to me all the time here at How-To Geek.…

立即通过Xumo.TV在线观看免费电视

Xumo.TV brings the channel surfing experience to cord cutters, with content from The History Channel, MSNBC, Fox Sports, and more. And it’s free. Xumo.TV将频道浏览体验带给剪线钳&#xff0c;其中包括The History Channel&#xff0c;MSNBC&#xff0c;Fox Sports…

NOIP2009靶形数独

试题描述小城和小华都是热爱数学的好学生&#xff0c;最近&#xff0c;他们不约而同地迷上了数独游戏&#xff0c;好胜的他们想用数独来一比高低。但普通的数独对他们来说都过于简单了&#xff0c;于是他们向 Z 博士请教&#xff0c; Z 博士拿出了他最近发明的“靶形数独”&…

h5输出文字write_免费下载:Write是用于手写的文字处理器

h5输出文字writeWindows/Mac/Linux/Android: Love the feel of writing by hand, but wish you could use features like copy/paste and undo? Write is a free tool that lets you do just that. Windows / Mac / Linux / Android&#xff1a;喜欢手写的感觉&#xff0c;但是…

11. IDEA 在同一工作空间创建多个项目

1.创建项目 二.、创建工作空间 JavaWorkspace 1、File-> New Project -> 创建工作空间 JavaWorkspace&#xff0c;并 顺便创建项目 JavaOne 2.创建第一个项目后形成的目录结构如下 三、在已经创建好的工作空间中创建第二个项目 1、File -> New Module -> 创建项目 …

winform 线程监听两个目录下的文件_vb.net 利用.net自带的GZipStream压缩或者解压文件的代码,不需要任何第三方控件...

网上很少有用VB写的压缩文件的代码&#xff0c;但是&#xff0c;在网络传输&#xff0c;文件下载,打包发布等等方面的需求又比较多&#xff0c;所以&#xff0c;借鉴了一下C#代码的例子&#xff0c;改造成了VB用的类。另外加上了多层文件夹压缩解压。但是&#xff0c;因为时间有…

什么是“ rpcsvchost”,以及为什么它在Mac上运行?

You find something called rpcsvchost while using Activity Monitor to see what’s running on your Mac. What is this process, and should you be worried? In a word, no: rpcsvhost is a core part of macOS. 在使用“活动监视器”查看Mac上正在运行的内容时&#xff…

自定义异常禁用异常堆栈_如何在Mac上禁用或自定义自动更正

自定义异常禁用异常堆栈Sometimes, autocorrect gets it wrong, replacing a word you meant to type with something completely different. You can customize it to fix these issues or disable it altogether. 有时候&#xff0c;自动更正会把它弄错&#xff0c;用完全不同…

控制dcom程序使用端口_使用VS Code调试.net控制台应用程序的方法

本文由 比特飞 原创发布&#xff0c;欢迎大家踊跃转载。转载请注明本文地址&#xff1a;https://www.byteflying.com/archives/6928。1、概述本文向大家介绍使用Visual Studio Code调试.net控制台应用程序的方法。2、方案首先在创建好一个控制台应用程序&#xff0c;再在扩展中…

4khz的带宽是指什么意思_扬声器和耳机的Hz-KHz范围是什么意思?

4khz的带宽是指什么意思If you’ve looked at high-end headphones or speakers, you’ve probably noticed numbers on the spec sheet that read something like “20Hz-20KHz.” What do these numbers mean? 如果您看过高端耳机或扬声器&#xff0c;则可能已经注意到规格表…