#跨表查用__,跨表取用.
ForeignKey
ManyToMany
models.listname.objects.filter(ForeignKeyList__requestname = ‘‘)
userinfo.objects.filter(usertype__id__gt = 5)
userinfo.objects.filter(usertype__name__contain = ‘A‘)
多对多
u1 = UserInfo.objects.get(id = 1)
g1 = UserGroup.objects.get(id =1)
""g1.user.add(u1)
""u1.usergroup_set.add(g1)
from djang.utils.safestring import mark_safe
session cookie
request.session[key] = value
render_to_response().set_cookie(key:value)
request.cookie.get
request.session.get
跨站请求伪造
html :
{%csrf_token%}
后端:
from django.template.context import RequestContext
context_instance = RequsetContext(request)
自定义中间件:
class OneClass(object):
def process_requset(self,request):#第一个
pass
def process_view(self,request,callback,callback_argv):#第二个
pass
def process_exception(self,request,exception):#第三个
pass
def process_response(self,request,response):#第四个
pass
return response
多个中间件:
class1.process_requset
class2.process_requset
==类似
django admin
models.class.
原文:http://www.cnblogs.com/wangyong1027/p/5107699.html