上药三品,神与气精

曾因酒醉鞭名马 生怕情多累美人


  • 首页

  • 关于

  • 分类

  • 标签

  • 归档

  • 搜索

javascript foundation

发表于 2017-11-29 | 阅读次数:
字数统计: 189 | 阅读时长 ≈ 1

js的分层

jquery tool
组件 ui
应用 app
mvc backboneJS

js的规划

避免全局变量和方法(命名空间 闭包 面向对象)

模块化

常用内部类:Data Array Math String

HTML属性,CSS属性
HTML:属性.HTML属性=”值”;
CSS:对象.style.CSS属性=”值”;

class和float

1.class:className
2.float:cssFloat

获取对象

id:document.getElementById(“id 名”)

事件:用户的动作

鼠标事件:
onclick:点击
onmouseover: 鼠标放上
onmouseout:鼠标离开
ondbclick:双击事件
onmousedown:鼠标按下
onmouseup:鼠标抬起
onmousemove鼠标移动

表单事件:
onfocus:获取焦点
onblur:失去焦点
onsubmit:提交事件
onchange:当发生改变的时候
onreset:重置事件

键盘事件:
onkeyup:键盘抬起
onkeydown:键盘按下
onkeypress:键盘按键一次
窗口时间:onload事件

scrapy middleware

发表于 2017-11-28 | 阅读次数:
字数统计: 152 | 阅读时长 ≈ 1

scrapy 常用的中间件 总结

名称 功能
retry 重试可能由于临时问题引起的超时问题
cookie 该中间件使得爬取需要cookie(例如使用session)的网站成为了可能。 其追踪了web server发送的cookie,并在之后的request中发送回去, 就如浏览器所做的那样。
DefaultHeadersMiddleware 头设置为默认模式
downloadtimeout 设置超时
httpauth 对来自特定spider的request授权
httpcache 給request&response设置缓存策略
httpproxy 給所有request设置http代理
redirect 重定向
metarefresh 根据meta-refresh html tag处理重定向
robotsTxt robots封禁处理

cookie and session

发表于 2017-11-28 | 分类于 web | 阅读次数:
字数统计: 709 | 阅读时长 ≈ 2

Cookie和Session

  1. 由于HTTP协议是无状态的协议,所以服务端需要记录用户的状态时,就需要用某种机制来识具体的用户,这个机制就是Session.典型的场景比如购物车,当你点击下单按钮时,由于HTTP协议无状态,所以并不知道是哪个用户操作的,所以服务端要为特定的用户创建了特定的Session,用用于标识这个用户,并且跟踪用户,这样才知道购物车里面有几本书。这个Session是保存在服务端的,有一个唯一标识。在服务端保存Session的方法很多,内存、数据库、文件都有。集群的时候也要考虑Session的转移,在大型的网站,一般会有专门的Session服务器集群,用来保存用户会话,这个时候 Session 信息都是放在内存的,使用一些缓存服务比如Memcached之类的来放 Session
  1. 思考一下服务端如何识别特定的客户?这个时候Cookie就登场了。每次HTTP请求的时候,客户端都会发送相应的Cookie信息到服务端。实际上大多数的应用都是用 Cookie 来实现Session跟踪的,第一次创建Session的时候,服务端会在HTTP协议中告诉客户端,需要在 Cookie 里面记录一个Session ID,以后每次请求把这个会话ID发送到服务器,我就知道你是谁了。有人问,如果客户端的浏览器禁用了 Cookie 怎么办?一般这种情况下,会使用一种叫做URL重写的技术来进行会话跟踪,即每次HTTP交互,URL后面都会被附加上一个诸如 sid=xxxxx 这样的参数,服务端据此来识别用户
  1. Cookie其实还可以用在一些方便用户的场景下,设想你某次登陆过一个网站,下次登录的时候不想再次输入账号了,怎么办?这个信息可以写到Cookie里面,访问网站的时候,网站页面的脚本可以读取这个信息,就自动帮你把用户名给填了,能够方便一下用户。这也是Cookie名称的由来,给用户的一点甜头。

  2. 所以,总结一下:

Session是在服务端保存的一个数据结构,用来跟踪用户的状态,这个数据可以保存在集群、数据库、文件中;

Cookie是客户端保存用户信息的一种机制,用来记录用户的一些信息,也是实现Session的一种方式

生产环境下,nginx将请求分发给多个后端uwsgi进程,而不是线程...

开发服务器runserver从1.4开始就是单进程多线程的了。

js-foundation

发表于 2017-11-27 | 阅读次数:
字数统计: 369 | 阅读时长 ≈ 1

1.javascript 的数据类型都有哪些?

null 表示“没有对象”,即该处不应该有值。
(1) 作为函数的参数,表示该函数的参数不是对象。
(2) 作为对象原型链的终点。

Object.getPrototypeOf(Object.prototype)// null

获取元素时,如果当前文档中特定元素不存在则返回null.

undefined表示”缺少值”,就是此处应该有一个值,但是还没有定义。典型用法是:
(1)变量被声明了,但没有赋值时,就等于undefined。
(2) 调用函数时,应该提供的参数没有提供,该参数等于undefined。
(3)对象没有赋值的属性,该属性的值为undefined。
(4)函数没有返回值时,默认返回undefined。

引用数据类型:Object(Array,Date,RegExp,Function)

数组数据类型:

function isArrayFn(value){  
    if (typeof Array.isArray === "function") {  
        return Array.isArray(value);      
    }else{  
        return Object.prototype.toString.call(value) === "[object Array]";      
    }  
}

2.已知ID的Input输入框,希望获取这个输入框的输入值,怎么做?(不使用第三方框架)

document.getElementById(“ID”).value

3.希望获取到页面中所有的checkbox怎么做?(不使用第三方框架)

var domList = document.getElementsByTagName(‘input’)
var checkBoxList = [];
var len = domList.length;  //缓存到局部变量
while (len--) {  //使用while的效率会比for循环更高
  if (domList[len].type == ‘checkbox’) {
      checkBoxList.push(domList[len]);
  }
}

4.设置一个已知ID的DIV的html内容为xxxx,字体颜色设置为黑色(不使用第三方框架)

var dom = document.getElementById(“ID”);
dom.innerHTML = “xxxx”;
dom.style.color = “#000”;    

django-template-3

发表于 2017-11-27 | 分类于 web | 阅读次数:
字数统计: 1.8k | 阅读时长 ≈ 8

标签

  • 标签的形式是: 标签要比变量复杂

  • 标签的作用

    在输出时创建一些文本
    通过执行循环和一些逻辑来实现控制流
    装载一些外部信息进入模板

  • 内建标签

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
autoescape  
使用形式:
{% autoescape off %}
(内容)
{% endautoescape %}
意义:当某块内容不需要自动转义的时候,这样写就可以了。当然如果块内某些地方需要转义的话,调用filter也可以。

block
使用形式:
{% block %}
(定义块内容)
{% endblock %}
意义:定义一个块,该块能够被继承他的子孙模板重写

comment
使用形式:
{% comment %}
(内容)
{% endcomment %}
意义:模板系统会忽略该标签内部的所有内容。

cycle
使用形式:
例如:
<tr class="{% cycle list%}">
...
</tr>
意义:在循环时轮流使用给定的字符串列表中的值。

extends
使用形式:{% extends "base.html" %}或者{% extends variable %}变量可以是一个字符串,也可以是一个模板对象。
意义:表示本模板要对指定的父模板进行扩展。

filter
使用形式:
{%filter force_escape|lower%}
(内容)
{%endfilter%}
意义:将filter 标签圈定的内容执行过滤器操作。

firstof
使用形式:{%firstof var1 var2 var3%}
意义:输出第一个值不等于False的变量
等价于:
{% if var1 %}
{{ var1 }}
{% else %}
{% if var2 %}
{{ var2 }}
{% else %}
{% if var3 %}
{{ var3 }}
{% endif %}
{% endif %}
{% endif %}

for
使用形式:
{% for variable in list/dict %}
(使用variable)
{% endfor%}
意义:循环list中的每个值,进行相应的输出
注意:
(a)也可以反向遍历{% for variable in list/dict reversed %}
(b)也可以{% for x, y in points %} points中的每个元素为 (x,y)
(c)也可以{% for key,value in data.items %} data是一个dictionary
for loop中定义的一些内建变量
forloop.counter 当前的迭代器数目(从1开始)
forloop.counter0 当前的迭代器数目(从0开始)
forloop.revcounter 当前的反向迭代器数目(从1开始)
forloop.revcounter0 当前的反向迭代器数目(从0开始)
forloop.first 值为True,如果是第一次通过迭代器
forloop.last 值为True,如果是最后一次通过迭代器
forloop.parentloop 对于嵌套循环,这是当前循环的上一层循环

for ... empty
使用形式如下:
{% for varibale in list %}
(内容1)
{% empty %}
(内容2)
{% endfor %}
意义:当list是空的时候,能够执行内容2,其形式等同于,先if判断list是否存在,然后在根据情况做什么操作。

if
使用形式如下 :
{% if variable %}
(内容1)
{% else %}
(内容2)
{% endif %}
注意:variable中可以使用and or 或者not,但是有一条必须记住,就是不允许and 和 or一起使用

ifchanged
使用形式:
(a)如果直接检测循环变量是否变化,那么使用:
{% ifchanged %}
(内容)
{% endifchanged %}
(b)如果检测循环变量的某个dot变量,例如循环变量是date,那么检测date.hour,那么使用:
{% ifchanged date.hour %}
(内容)
{% endifchanged %}
(c)ifchanged也可以加上一个{% else %}语句
意义:检测本次循环的值和上一次循环的值一样不一样,只能用在循环里面。

ifequal
使用形式:
{% ifequal variable1 variable2 %}
...
{% endifequal %}
意义:判断两个变量是否相等。

ifnotequal
使用与(12)相同

include
使用形式:{% include "foo/bar.html" %}或者{% include template_name %}
意义:将另外一个模板文件中的内容添加到该文件中。注意区别extend是继承。

now
使用形式:{% now "jS F Y H:i "%},注意存在需要转义的情况例如{% now "jS o\f F" %},因为f是格式化字符串
具体的格式化字符串如下所示


a 'a.m.' or 'p.m.' (Note that this is slightly different than PHP's output, because this includes periods to match Associated Press style.) 'a.m.'
A 'AM' or 'PM'. 'AM'
b Month, textual, 3 letters, lowercase. 'jan'
B Not implemented.
d Day of the month, 2 digits with leading zeros. '01' to '31'
D Day of the week, textual, 3 letters. 'Fri'
f Time, in 12-hour hours and minutes, with minutes left off if they're zero. Proprietary extension. '1', '1:30'
F Month, textual, long. 'January'
g Hour, 12-hour format without leading zeros. '1' to '12'
G Hour, 24-hour format without leading zeros. '0' to '23'
h Hour, 12-hour format. '01' to '12'
H Hour, 24-hour format. '00' to '23'
i Minutes. '00' to '59'
I Not implemented.
j Day of the month without leading zeros. '1' to '31'
l Day of the week, textual, long. 'Friday'
L Boolean for whether it's a leap year. True or False
m Month, 2 digits with leading zeros. '01' to '12'
M Month, textual, 3 letters. 'Jan'
n Month without leading zeros. '1' to '12'
N Month abbreviation in Associated Press style. Proprietary extension. 'Jan.', 'Feb.', 'March', 'May'
O Difference to Greenwich time in hours. '+0200'
P Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off if they're zero and the special-case strings 'midnight' and 'noon' if appropriate. Proprietary extension. '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
r RFC 2822 formatted date. 'Thu, 21 Dec 2000 16:01:07 +0200'
s Seconds, 2 digits with leading zeros. '00' to '59'
S English ordinal suffix for day of the month, 2 characters. 'st', 'nd', 'rd' or 'th'
t Number of days in the given month. 28 to 31
T Time zone of this machine. 'EST', 'MDT'
U Not implemented.
w Day of the week, digits without leading zeros. '0' (Sunday) to '6' (Saturday)
W ISO-8601 week number of year, with weeks starting on Monday. 1, 53
y Year, 2 digits. '99'
Y Year, 4 digits. '1999'
z Day of the year. 0 to 365
Z Time zone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.




spaceless
使用形式:{% spaceless %}
(内容)
{% endspaceless %}
意义:删除包围内容中的所有tab或者回车字符。

template
使用形式:{% templatetag %}
意义:模板系统本身没有转义的概念,因此如果要输出一个像“{%”这样的东东,就需要采用这种方式,否则就会语法错误
其参数有:
openblock {%
closeblock %}

openvariable {{
closevariable }}

openbrace {
closebrace }

opencomment {#
closecomment #}

with
使用形式:
{% with "expensive var1" as var2 %}
{% endwith %}
意义:当一个变量的访问消耗很大的模板解析时,可以用另外一个变量替换它,这种替换只有在with内部有效。

url
使用形式:{% url path.to.some_view arg1,arg2 %}
意义:给定某个module中函数的名字,给定参数,那么模板引擎给你一个URL,从而避免硬编码URL到代码中
注意:前提是URLconf中存在相应的映射,如果URLconf中没有该映射,那么会抛出异常,
这是可以选择使用
{% url path.to.view arg1 ,arg2 as the url %}
<a href="{{ the_url }}">Link to optional stuff</a>
其实这相当于
{% url path.to.view as the\_url %}
{% if the_url %}
<a href="{{ the_url }}">Link to optional stuff</a>
{% endif %}
1…99100101…109
John Cheung

John Cheung

improve your python skills

543 日志
33 分类
45 标签
RSS
GitHub Email
© 2020 John Cheung
本站访客数:
|
主题 — NexT.Pisces v5.1.4
博客全站共226.3k字