PYTHON第七十三天笔记12.6-星期三
一、自记录
登录、注册错误时出现提示信息,不会刷新页面:是用ajax处理的。
二、课上笔记
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
Django: URL控制器: url配置: 注意:url:匹配的是url的路径部分 import re re.findall("^articls/2004/$","articls/2004/asdsa") 无名分组: # url(r'^articls/(\d{4})/(\d{2})$', views.archive3,), # archive2(request,2000,11) 有名分组: # url(r'^articls/(?P<y>\d{4})/(?P<m>\d{2})$', views.archive4,), # archive2(request,y=2000,m=11) name参数: url(r'^login.html/', views.login,name="Login"), # login(request) in template: action="{% url 'Login' %}" <a href='{% url 'Login' %}'>click</a> views模块: def foo(request): #逻辑代码 return 请求对象Request request.body------字节串 request.POST request.GET request.method request.COOKIE request.session request.path 响应对象 Httpresponse render(渲染方法) render(request,"index.html",{"name":name}) redirect(重定向) 以登录为例: 第一次请求: 请求url: http://127.0.0.1:8000/login.html/ GET 无请求数据 login.html/-------> views.login------>login() 响应到一个login.html页面 第二次请求: 请求url: http://127.0.0.1:8000/login.html/ POST 有请求数据 {"user":"alex","pwd":"123"} login.html/-------> views.login------>login() 响应的return redirect("/index/")到浏览器,通知浏览器再发送请求:"/index/" 请求url: http://127.0.0.1:8000/index/ get请求 没有数据 index/ --->url(r'^index/', views.index),---->index() 响应一个index.html template(模板语法): 渲染变量: {{}} ----深度查询 句点符 . ----过滤器 {{var|filter_name:参数}} date slice 标签 --- {% for i in obj %} {%endfor%} ---- {% if a == 10 %} ... {% elif a > 10%} ... {% else %} ... {% endif%} ---- {{business.employees.count}} 补充: form ajax ------提交post请求时,如何防止跨域 {% csrf_token %}--------<input type="hidden" name="csrfmiddlewaretoken" value="8hqV5BFiFmSoPdzGM18I2yaEXtlLLn7nx8Kj8W1OUg7D3T9YSK3JkNdqXHr9nyiu"> 继承: (1)创建base.html , 构建block {%block content %} {% endblock content%} (2)创建子模板,{%extends 'base.html'%} {%block content %} .... {% endblock%} ---- {{ block.super }} 继承盒子中的内容 ORM: 映射关系: python的类名对应的SQL语句的表名 python的类属性对应的SQL语句的表名下的字段 python的类属性的约束对应的SQL语句的表名下的字段类型 类的实例对象---------------表中的一条记录 第一步:创建表 作业: 1、学员管理系统: 流程 2、<a href="/del/{{}}">删除</a> def foo(): id=request.GEt.get("s_id")
三、课上图片
1 过滤safe禁止防xss攻击
2
3.1
3.2
3.3
4.1 只要是符合json标准的字符串就可以
4.2
4.3
4.444
4.445
5
6