form is_valid():执行顺序:
![](index_files/2e0a34ac-663e-41b5-87b3-01f20c020245.jpg)
![](index_files/261e51b4-e8d0-4cbf-906d-b29d0d939c5c.jpg)
![](index_files/6b5ec346-3046-4628-898d-95b23c51a062.jpg)
前面的注册与登录都写完了,但是心中一致有一个困惑,那就是
<wiz_code_mirror>
1
if reg_form.is_valid():
这段神奇的代码,怎么就帮我们完成了对用户输入内容的校验啦?让我们一探究竟。
1、首先 Ctrl+左键 点击进入 is_valid()函数查看源码
![](index_files/786f7629-1160-4189-a508-761fce026904.jpg)
2、点击is_bound
![](index_files/88b99beb-206d-42d2-92da-2afd16f60741.jpg)
![](index_files/1b6360f3-909c-4319-a7b0-efe2d75f076b.jpg)
就是在实例化的时候只要form_obj = RegForm(request.POST)括号里面只要有数据那么.is_bound永远True
![](index_files/814e40f8-94d2-4ccf-9c17-6c6656d0df20.jpg)
![](index_files/26d62542-f895-4162-95a5-19d30b74beed.png)
3、点击进入self.errors()
![](index_files/25e9e3d7-027d-4989-8a7f-81657fdf692c.jpg)
![](index_files/1c86913b-cab4-46ed-8a3f-b0f31040f966.jpg)
![](index_files/d476b90f-0e19-428d-92ca-603ee6b8f75a.jpg)
4、点击进入self.full_clean()
![](index_files/9fc0c06c-f40f-4a70-96b3-e1198cb73e07.jpg)
5、点击进入ErrorDict
![](index_files/ed8c73c3-cb18-4653-a904-b49f8890cf5e.jpg)
![](index_files/c5666992-fd98-46ba-9a93-bc237e955325.jpg)
其实在这里就只是校验了 reg_form = RegForm(request.POST) 实例对象里面有没有值而已
![](index_files/1bf3c4f0-75ee-434a-9b8f-0c45b9db3b6d.jpg)
记下来就是根据我们自定义的校验规则来做校验了!
![](index_files/086319db-fac9-41d2-851d-67220ee674b1.png)
然后在点击进入
![](index_files/21da5908-66fd-485c-a40b-52c966ff64ec.jpg)
![](index_files/db8d0ec3-4efa-423e-a5b3-80c36ab0b48a.jpg)
![](index_files/066fe1ec-e7a6-4e66-9e6b-f43b7290613c.jpg)
![](index_files/1a4b30a9-72c0-4040-850d-69193a6f6a3e.jpg)
![](index_files/8d9f020f-edf9-4394-ae83-c79301788df8.jpg)
![](index_files/be0cbb77-9843-470e-abee-6484ba8eaf3e.png)
![](index_files/2a8d87a0-13d3-4928-a0a9-fafce7c74fc1.jpg)
![](index_files/440d85b6-f4c9-4d12-8520-c4a8bfe8cd79.jpg)
![](index_files/1bf3c4f0-75ee-434a-9b8f-0c45b9db3b6d.jpg)
![](index_files/7df5fca4-6bf4-40f5-ab09-41df1ebbb139.jpg)
![](index_files/ee7f683a-ef4f-40c6-8a26-6e9c3e187f35.jpg)
![](index_files/ef7e7043-9b81-4529-84f7-66fd61921252.jpg)
![](index_files/1205a16e-90f2-490f-925b-49643701e1f4.jpg)
![](index_files/f61521b5-1078-457f-bd0b-ecfcfed0aa4e.jpg)
![](index_files/a0d2dc18-cb75-4c8e-9073-dc4d4a0f0c6b.jpg)
![](index_files/8c0f85cb-76c1-4328-9af9-481e0b598088.jpg)
![](index_files/5bce1733-37ef-40f9-b889-5ce9e6f97502.jpg)
![](index_files/edab63ea-77de-40e9-889b-6ac5e33d3996.jpg)
![](index_files/11b4c533-dc62-438d-a661-52a50518ecb9.jpg)
![](index_files/c4d7f432-e661-41b2-b1ce-5af6e37aa20d.jpg)
![](index_files/bbb2881e-2e85-469d-bb82-3c048dae9099.png)
当我们重写父类的clean()方法时
![](index_files/c1d18530-1857-415b-b8a0-d8b951a47d9d.jpg)
![](index_files/e2cfbb79-0838-46d5-863f-a1f671ca6279.jpg)
![](index_files/0fd5b75a-a057-4f9b-9fd9-750c057f61d8.jpg)
![](index_files/7d12e9c3-4b5e-4f8c-ad60-5696050458e7.jpg)
![](index_files/ca048fb6-09c0-432e-99b9-6eea77e7ebdc.jpg)
如何将两次输入密码不一致的信息传给模版页面啦?
![](index_files/24d7f618-a48c-46bc-88cc-97c0bb934cd0.jpg)