标签:class end ota port new tor 操作 html views
一、视图CBV
1.urls
url(r‘^login.html$‘, views.Login.as_view()),
2.views
from django.views import View
class Login(View):
def get(self,request):
return HttpResponse(‘from get‘)
def post(self,request):
return HttpResponse(‘from post‘)
二、ORM补充
正向操作
result = models.UserInfo.objects.all()
for obj in result:
print(obj.name,obj.age,obj.ut_id,obj.ut.title,obj.ut.fo.new_name)#通过点外键名进行连表操作ut和fo都是外键名
反向操作
obj = models.UserType.objects.all().first()
print(obj.id,obj.title,obj.userinfo_set_all()) # obj.userinfo_set_all()匹配用户类型相关的所有用户
for row in obj.userinfo_set_all(): #遍历每一个用户对象
print(row.name,row.age)
三、分页
分批获取数据
userinfo_list = models.UserInfo.objects.all()[0,10]
from django.core.paginator import Page,Paginator,PageNotAnInteger
current_page = request.GET.get(‘page‘)--
# current_page = int(current_page)
user_list = models.UserInfo.objects.all()
paginator = Paginator(user_list,10)
try:
posts = paginator.page(current_page)
except PageNotAnInteger as e:
posts = paginator.page(1)
return render(request,‘index.html‘,{‘posts‘:posts})
标签:class end ota port new tor 操作 html views
原文地址:http://www.cnblogs.com/guotianbao/p/7482273.html