Rest_framework-1】的更多相关文章

前言: 最近工作中需要用到Django rest_framework框架做API, 边学边写,记录了一些实际工作中需要用到的功能,不是很全也不系统,以后需要什么功能可以在这查询. 后续还会更新其它的用法 #################################################################### ########安装和简单使用 ###### 准备工作 pip install rest_framework # 安装 INSTALLED_APPS = (…
rest_framwork 之post 与put rest_framwork可以接受post与put delete get请求,可以对资源进行刚CRUD,以一个DEMO为例, 1.先在VIEW里定义一个方法 @api_view(['GET', 'PUT', 'DELETE']) def book_detail(request,pk): """ Retrieve, update or delete a book instance. """ try:…
接上文 这里先写一个GET请求的 1.先在VIEW里定义一个方法 代码如下: @api_view(['GET', 'POST']) def book_request(request): if request.method == 'GET': queryset = Book.objects.all() serializer_class = BookSerializer serializer = BookSerializer(queryset) return Response(serializer.…
环境 django 1.6,rest_framework 3.3 ubuntu采用pip安装的rest_framework 按照例子一步步做下来 运行 提示filters.py第119行有错误forms.UUField找不到,查找了下好像上下问并没有使用UUIDFilter这个,注释掉 这个时候错误变成了No module named http_client 没道理一安装有这么多错误,Bing之发现有人说是版本不匹配,从服务起down了一个2.4.x下来setup了 错误变成了'module'…
余下的就是静心看官方文档了. 这个是最抽象的了. urls.py """tutorial URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.8/topics/http/urls/ Examples: Function views 1. Add an import:…
urls.py from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patterns from snippets import views urlpatterns = [ url(r'^$', views.api_root), url(r'^snippets/$', views.SnippetList.as_view(), name='snippet-list'), url(r…
哈哈,终于快结束了.. urls.py from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^', include('snippets.urls')), ] urlpatterns += [ url(r'^api-auth/', include('rest_framewo…
一层一层的封装,又能到底层,就会有全局感啦... from rest_framework import status from rest_framework.response import Response from snippets.models import Snippet from snippets.serializers import SnippetSerializer from django.http import Http404 from rest_framework.views i…
优化前和优化后的代码,融在一起,能看看进化的过程. MODELS.PY from django.db import models from pygments.lexers import get_all_lexers from pygments.styles import get_all_styles LEXERS = [item for item in get_all_lexers() if item[1]] LANGUAGE_CHOICES = sorted([(item[1][0], ite…
我想,其它几个基于PYTHON的REST API模块概念都差不多吧. 先深入搞定这个吧. 前几次练习完了有一些印象,并且在工作中实践过一个,现在多弄几次,玩熟悉点. Serializers.py __author__ = 'CHENGANG882' from django.contrib.auth.models import User, Group from rest_framework import serializers class UserSerializer(serializers.Hy…