文章分类 -  Django

摘要:class ModelIterable(BaseIterable): """Iterable that yields a model instance for each row.""" def __iter__(self): queryset = self.queryset db = queryse 阅读全文
posted @ 2018-11-18 17:27 十七楼的羊 阅读(259) 评论(0) 推荐(0)
摘要:class ModelBase(type): """Metaclass for all models.""" def __new__(cls, name, bases, attrs, **kwargs): super_new = super().__new__ # Also ensure initi 阅读全文
posted @ 2018-11-18 11:12 十七楼的羊 阅读(1344) 评论(0) 推荐(0)
摘要:import logging from django.conf import settings from rest_framework.authentication import ( BaseAuthentication, get_authorization_header, ) from rest_ 阅读全文
posted @ 2018-11-10 17:59 十七楼的羊 阅读(240) 评论(0) 推荐(0)
摘要:from __future__ import unicode_literals import os import pkgutil import sys from collections import OrderedDict, defaultdict from importlib import imp 阅读全文
posted @ 2018-11-08 16:02 十七楼的羊 阅读(680) 评论(0) 推荐(0)
摘要:class WSGIHandler(base.BaseHandler): request_class = WSGIRequest def __init__(self, *args, **kwargs): super(WSGIHandler, self).__init__(*args, **kwarg 阅读全文
posted @ 2018-09-13 16:14 十七楼的羊 阅读(272) 评论(0) 推荐(0)
摘要:# -*- coding: utf-8 -*- import logging from django.conf import settings from django.contrib.auth import authenticate from django.contrib.auth.models i 阅读全文
posted @ 2018-09-13 09:59 十七楼的羊 阅读(206) 评论(0) 推荐(0)
摘要:首先 定义试图类 class SessionView(APIView): permission_classes = () def get(self, request): user = request.user if isinstance(user, AnonymousUser): raise Aut 阅读全文
posted @ 2018-09-11 18:07 十七楼的羊 阅读(1593) 评论(0) 推荐(0)
摘要:# -*- coding: utf-8 -*- import logging import sys '''常见logging用法''' # 获取logger实例,如果参数为空则返回root logger # logger 是全局变量 ,要保证调用一次,调用得多了,就会重复实现! # 在 flask之 阅读全文
posted @ 2018-08-28 11:24 十七楼的羊 阅读(284) 评论(0) 推荐(1)
摘要:给予token的验证机制:(是将加密存储到浏览器之上的.) 用户使用用户名密码来请求服务器 服务器进行验证用户的信息 服务器通过验证发送给用户一个token 客户端存储token,并在每次请求时附送上这个token值 服务端验证token值,并返回数据给予session的验证机制(是存储到服务器(内 阅读全文
posted @ 2018-07-06 22:57 十七楼的羊 阅读(149) 评论(0) 推荐(0)
摘要:首先前端发送请求,nginx 服务器的发送请求,WSGI接受请求,并且将请求发送给框架,然后调用中间件为请求的数据进行封装!也就是request.user的由来! 1),当Django运行在生产模式时,将不再提供静态文件的支持,需要将静态文件交给静态文件服务器。2),WSGI 的作用就是把 web 服务器和 web 框架 (Django) 连接起来 #我的模块是 books下的app,所以文件的... 阅读全文
posted @ 2018-07-03 11:08 十七楼的羊 阅读(495) 评论(0) 推荐(0)
摘要:2,django设置了多个保存点用来回退事务以及提交事务操作! 阅读全文
posted @ 2018-07-03 09:43 十七楼的羊 阅读(216) 评论(0) 推荐(0)
摘要:''' 可以达到这样的效果! { 1001(sku_id): { "count": 10, "selected": true}, ... } ''' from django_redis import get_redis_connection conn = get_redis_connection(' 阅读全文
posted @ 2018-06-30 15:17 十七楼的羊 阅读(487) 评论(0) 推荐(0)
摘要:首先理解同步与异步 1,计算机之中的同步是现实生活之中的异步,异步是现实生活之中的同步 2,同步与异步关注的是消息通信机制,对于同步而言,就想浏览器请求服务器的过程,是一直等待服务器返回数据。 异步指的是,当向浏览器发送请求,如果服务器忙,会等到空闲时候告诉你(这个过程就称之为使用回调函数) 阻塞与 阅读全文
posted @ 2018-06-27 21:49 十七楼的羊 阅读(125) 评论(0) 推荐(0)
摘要:1,get_queryset() 是更改返回的数据,不以默认的 序列化类字段返回!返回的是指定的查询集,如果只是详情页也就是 ListAPIView,不需要指定 get_object() # url(r'^areas/(?P<pk>\d+)/$', views.AreasViewSets.as_vi 阅读全文
posted @ 2018-06-26 11:24 十七楼的羊 阅读(994) 评论(0) 推荐(1)
摘要:2,DestroyAPIView继承了GenericAPIView、DestoryModelMixin 阅读全文
posted @ 2018-06-24 17:23 十七楼的羊 阅读(139) 评论(0) 推荐(0)
摘要:REST framework 提供了众多的通用视图基类与扩展类,以简化视图的编写。REST framework 与请求类型相关联,只有符合 DRF需要的请求类型才能调用视图函数 1,APIView 主要是封装了request 与 HttpRequeset 对象! 视图图会为响应数据设置(render)符合前端要求的格式; 2,GenericAPIView 是 APIView 的子类 '''... 阅读全文
posted @ 2018-06-24 17:13 十七楼的羊 阅读(132) 评论(0) 推荐(0)
摘要:Responses 默认是调用的是 render 实现达到渲染的目的!前端请求 字段 Accept 指定希望得到的数据类型!或者在 url 后缀之中指定结尾类型,也就是希望返回的类型! #在setting 指定返回类型 REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': ( 'rest_framework.renderers.J... 阅读全文
posted @ 2018-06-21 11:04 十七楼的羊 阅读(203) 评论(0) 推荐(0)
摘要:REST_FRAMEWORK = { # 使用第三方扩展 djangorestframework-jwt 代替cookie 进行身份验证! 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTo 阅读全文
posted @ 2018-06-20 22:54 十七楼的羊 阅读(175) 评论(0) 推荐(0)
摘要:1,以后的django项目都是在DRF框架的之上的 2,setting文件下dev之中添加添加redis CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://127.0.0. 阅读全文
posted @ 2018-06-19 23:10 十七楼的羊 阅读(148) 评论(0) 推荐(0)
摘要:1,使用在urlpatterns=[]进行注册 2,通过路由类来进行拼接(适合在DRF之中使用) 路由类的vews.py的使用 阅读全文
posted @ 2018-06-17 09:15 十七楼的羊 阅读(800) 评论(0) 推荐(0)