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.pswp.cn/news/279250.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/279250.shtml
英文地址,請注明出處:http://en.pswp.cn/news/279250.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

mysql時間字段條件查詢_mysql 查詢 時間作為查詢條件

今天select * from 表名 where to_days(時間字段名) to_days(now());昨天SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 時間字段名) < 1近7天SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) < date(時間字段名)近30天SELECT * FROM 表名 whe…

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…

Swift5.1 語言參考(十) 語法匯總

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★?微信公眾號&#xff1a;山青詠芝&#xff08;shanqingyongzhi&#xff09;?博客園地址&#xff1a;山青詠芝&#xff08;https://www.cnblogs.com/strengthen/&#xff09;?GitHub地址&a…

timestamp mysql php_PHP和Mysql的Timestamp互換

在mysql中有三種時間字段類型&#xff1a;DATETIME&#xff0c;DATE和TIMESTAMP。DATETIME以YYYY-MM-DD HH:MM:SS格式的字符串來保存數據&#xff1b;DATE則是只有年月日以YYYY-MM-DD形式的字串&#xff1b;TIMESTAMP類型和PHP中的TIMESTAMP類型名字一樣&#xff0c;但是兩者基…

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 都可以走索引的&#…

HDU 3966 Aragorn's Story (樹鏈剖分+線段樹)

題意&#xff1a;給你一棵樹&#xff0c;然后有三種操作 I L R K: 把L與R的路徑上的所有點權值加上K D L R K&#xff1a;把L與R的路徑上的所有點權值減去K Q X&#xff1a;查詢節點編號為X的權值 思路&#xff1a;樹鏈剖分裸題&#xff08;我還沒有怎么學懂&#xff0c;但基本…

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…

mysql普通索引自增_mysql中聯合索引中的自增列的增長策略

《深入理解MySQL》中一段介紹MyISAM存儲引擎中自動增長列的示例,如下1 mysql>create table autoincre_demo2 -> (d1 smallint not nullauto_increment,3 -> d2 smallint not null,4 -> name varchar(10),5 ->index(d2,d1)6 -> )enginemyisam;7 Query OK, 0 r…

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.…

數據庫、表、表內容增刪改查

數據庫和表的創建 用戶的增 刪 改 查 增 create user 用戶名192.168.16.% identified by ‘123’&#xff1b;創建一個賬戶&#xff0c;并設置密碼&#xff0c;可不設密碼 grant all on *.* to 用戶地址; #給賬戶授權 flush privileges&#xff1b; #刷新授權立即生效 創…

立即通過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 博士拿出了他最近發明的“靶形數獨”&…

mysql 1005 - can't create table_關于創建數據表報錯一例(ERROR 1005 Can’t create table (errno: 121))...

問題描述曾遇到創建數據表報錯問題&#xff0c;報錯如下&#xff1a;ERROR 1005 (HY000) at line 18: Cant create table db1.t2 (errno: 121)通過日志查看有一條記錄InnoDB: Error: table db1.t2 already exists in InnoDB internal可見要創建的這個表已經存在&#xff0c;導致…