日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/9 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

總結

以上是生活随笔為你收集整理的2018-10-03-Python全栈开发-day60-django序列化-part3的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。