Today's Overview:
1. Cookies and Session
2, CSRF cross-site request forgery
3. Customizing paging
First, the previous section review: The nature of the HTTP request:
-HTTP request Nature Browser (socket client): 2. Socket.connect (IP, Port) 3. Socket.send ("http://www.xiaohuar.com/index.html ...") rule: HTTP protocol GET request: "get/index.html?k1=1&k2=2 http/1.1\r\nhost:www.xiaohuar.com\r\ncontent-type:application/json\r\n\r\n "Request header and request body use \r\n\r\n Split, front header, followed by Body POST request: "Post/index.html?k1=1&k2=2 http/1.1\r\nhost:www.xiaohuar.com\r\ncontent-type:application/json\r\n\r\ Nusername=alex&pwd=123123 "The request header and the request body are split using \r\n\r\n, the front header, followed by the body www.xiaohuar.com/index.html?k1=1&k2=26. Get the corresponding response header, response BODY = data.split (' \r\n\r\n ') 7. Disconnect Web site (socket service side): 1. Server run: IP, Port 4. string = Server.recv () header, BODY = Data.split ("\r\n\r\n=") request. Post.get () 5. Server response: Conn.send (' ... ') response header: Response body: 7. Disconnect Summary: A. The HTTP request is essentially a string B. HTTP request short Connection (request, response disconnected) c. Requests and responses are: header, body request: request Header \r\n\r\n Request Body Response: Response Header \r\n\r\n Response Body
ORM Table Operation Review:-Create TABLE: Line of Business-models.xx.objects.create (name= ' Canada ')-models.xx.objects.create (**dic)-Models.xx.objects.filter (id__ gt=1). Delete ()-Models.xx.objects.filter (id=1). Delete ()-Models.xx.objects.exclude (id=1). Delete ()- Models.xx.objects.filter (id=1). Update (name= ' DDD ')-Models.xx.objects.filter (id=1). Update (**DIC)-Create TABLE: Line of business host table ID Host port bs# Queryset = [Object, Object,...] -Objs = Models.xx.objects.all () for row in objs:row.idrow.hostrow.portrow.bs.name# Queryset = [{},{},...] -Objs = Models.xx.objects.all (). VALUES (' id ', ' host ', ' Port ', ' Bs__name ') for row in objs:row[' id ']row[' bs__name ']# Queryset = [(1,1.1.11,80, ' Web '), (), () ...] -Objs = Models.xx.objects.all (). Values_list (' id ', ' host ', ' Port ', ' bs__name ') #正向查找bs的名字 for row in objs:row[0]row[1] Model operation-CREATE TABLE: User table (ID, user,pwd,email,mm) line of business (ID, name) # User table _set Host table (ID host port BS) user line of Business relationship table (ID UID Bid) ****** 1 1 2 11-obj = modes.userinfo.objects.filter (user= ' Japanese elder brother '). First () Obj.mm.add (1) obj.mm.add (11) # Japanese brother responsible for the Line of business (line of Business objects), line of business object,]queryset = Obj.mm.all () for row in queryset:row.idrow.name-used car line of business is by those who are responsible for reverse lookup by object _set Method obj = Models.business_ Unit.objects.filter (name= ' used Cars '). First () Queryset = Obj.userinfo_set.all () #[user object, User object,]for row in Queryset: Row.userrow.pwd
Python Automation Development-[19th day]-pagination, cookie,session