choices参数、MTV与MVC模型、Ajax、序列化组件、sweetalert搭建页面、自定义分页器
一、Choices参数:
class User(models.Model): username = models.CharField(max_length=32) age = models.IntegerField() choices = ( (1,'男'),(2,'女'),(3,'其他') ) gender = models.IntegerField(choices=choices) """ 1 存choice里面罗列的数字与中文对应关系 print(user_obj.get_gender_display()) 只要是choices字段 在获取数字对应的注释 固定语法 get_choices字段名_display() 2 存没有罗列迟来的数字 不会报错 还是展示数字 """
二、MTV与MVC模型:
django框架 自称为是MTV框架
M:models
T:templates
V:views
MVC
M:models
V:views
C:controller 控制器(urls)
本质:MTV其实也是MVC
三、Ajax:不重新加载整个页面,与服务器交换数据,局部(js中技术)
异步提交,局部创新。
1、请求方式:GET 、POST
a标签href属性 GET请求
浏览器窗口号输入url GET请求
form表单 GET / POST
ajax GET / POST
基本ajax格式:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> </head> <body> <input type="text" id="i1"> + <input type="text" id="i2"> = <input type="text" id="i3"> <button id="b1">求和</button> <script> $('#b1').on('click',function () { $.ajax({ url: '', type:'post', data:{'i1':$('#i1').val(), 'i2':$('#i2').val()}, success:function (data) { {#alert(data);#} $('#i3').val(data) } }) }) </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> </head> <body> <input type="text" id="i1"> + <input type="text" id="i2"> = <input type="text" id="i3"> <button id="b1">求和</button> <script> $('#b1').on('click',function () { $.ajax({ url: '', type:'post', data:{'i1':$('#i1').val(), 'i2':$('#i2').val()}, success:function (data) { {#alert(data);#} $('#i3').val(data) } }) }) </script> </body> </html>
四、序列化组件:
五、sweetalert搭建页面:
六、自定义分页器: