Django_rest_framework_基础
简介
为什么要使用REST framework?
Django REST framework 是一个强大且灵活的工具包,用以构建Web APIs。
- 在线可视的API,对于赢得你的开发者们十分有用
- 验证策略涵盖了OAuth1a和OAuth2
- 同时支持ORM和非ORM数据源的序列化
- 可以配置各个环节,若无需更多强大的特性,使用一般基于类(function-based)的视图(views)即可
- 大量的文档,强力的社区支持
- 大公司如同Mozilla和Eventbrite,也是忠实的使用者
配置要求
REST framework 有以下的要求:
- Python (2.7, 3.2, 3.3, 3.4, 3.5)
- Django (1.7+, 1.8, 1.9)
下面是可选的包:
- Markdown (2.1.0+) - Markdown为可视化 API 提供了支持.
- django-filter (0.9.2+) - 过滤支持.
- django-crispy-forms - 为过滤,提供了改良的HTML呈现.
- django-guardian (1.1.1+) - 对象层面的权限支持.
安装与配置
安装
1
2
3
|
pip install djangorestframework pip install markdown # 可选依赖包 pip install django - filter # 可选依赖包 |
配置
1
2
3
4
5
6
7
8
9
10
|
INSTALLED_APPS = ( ... 'rest_framework' , ) REST_FRAMEWORK = { # 编码格式 'UNICODE_JSON' : False , } |
基本使用方法
models.py
1
2
3
4
5
6
7
|
from django.db import models class Author(models.Model): name = models.CharField(max_length = 32 ) age = models.IntegerField() def __str__( self ): return self .name |
urls.py
1
2
3
4
5
6
7
8
|
from django.conf.urls import url from django.contrib import admin from rest_demoimport views urlpatterns = [ url(r '^admin/' , admin.site.urls), url(r '^authors/$' , views.AuthorsView.as_view()), url(r '^authors/(\d+)/$' , views.AuthorsDetailView.as_view()), ] |
serializer.py
1
2
3
4
5
6
7
|
from rest_framework import serializers from rest_demo import models class AuthorModelSerializers(serializers.ModelSerializer): class Meta: model = models.Author fields = '__all__' |
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
from rest_demo import serializer from rest_framework.views import APIView from rest_framework.response import Response from rest_demo import models class AuthorsView(APIView): def get( self ,request): ''' 查询所有作者 :param request: :return: ''' author_list = models.Author.objects. all () auts = serializer.AuthorModelSerializers(author_list,many = True ) return Response(auts.data) def post( self ,request): ''' 添加作者 :param request: :return: ''' auts = serializer.AuthorModelSerializers(data = request.data) if auts.is_valid(): auts.save() return Response(auts.data) return Response(auts.errors) class AuthorsDetailView(APIView): def get( self ,request, id ): ''' 查询单条作者 :param request: :param id: :return: ''' author = models.Author.objects. filter (pk = id ).first() auts = serializer.AuthorModelSerializers(author) return Response(auts.data) def put( self ,request, id ): ''' 修改单条作者 :param request: :param id: :return: ''' author = models.Author.objects. filter (pk = id ).first() auts = serializer.AuthorModelSerializers(instance = author,data = request.data) if auts.is_valid(): auts.save() return Response(auts.data) return Response(auts.errors) def delete( self ,request, id ): ''' 删除单条作者 :param request: :param id: :return: ''' models.Author.objects. filter (pk = id ).delete() return Response() |
封装
继承mixin包下面的类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
from rest_framework import mixins from rest_framework import generics class PublishView(mixins.ListModelMixin,mixins.CreateModelMixin,generics.GenericAPIView): queryset = models.Publish.objects. all () serializer_class = serializer.PublishSerializers def get( self ,request, * args, * * kwargs): return self . list (request, * args, * * kwargs) def post( self ,request, * args, * * kwargs): return self .create(request, * args, * * kwargs) class PublishDetailView(mixins.RetrieveModelMixin,mixins.DestroyModelMixin,mixins.UpdateModelMixin,generics.GenericAPIView): queryset = models.Publish.objects. all () serializer_class = serializer.PublishSerializers def get( self ,request, * args, * * kwargs): return self .retrieve(request, * args, * * kwargs) def put( self ,request, * args, * * kwargs): return self .update(request, * args, * * kwargs) def delete( self ,request, * args, * * kwargs): return self .destroy(request, * args, * * kwargs) |
这个时候,我们只需要提供queryset和serializer_class两个参数配置,mixin包下面的类会帮我们处理数据,我们调用对应的方法并且将其返回值返回即可,
但是需要注意的是,如果使用此方法,urls.py的url对应的id要命名为pk,如下:
1
2
|
url(r '^publishes/$' , views.PublishView.as_view()), url(r '^publishes/(?P<pk>\d+)/$' , views.PublishDetailView.as_view()), |
但是,即使我们用了这种封装,很多代码还是有重复的,所有,rest_framework又给我们做了一层封装
继承generices包下面的类
只需要改变一下XXXView类的继承类
1
2
3
4
5
6
7
8
9
|
from rest_framework import generics class PublishView(generics.ListCreateAPIView): queryset = models.Publish.objects. all () serializer_class = serializer.PublishSerializers class PublishDetailView(generics.RetrieveUpdateDestroyAPIView): queryset = models.Publish.objects. all () serializer_class = serializer.PublishSerializers |
这样,代码就清晰很多了,但是,这种方法依然是将一个model表分成两个视图,那,有没有一种方法能将他们合并在一起呢?
继承viewsets包下的ModelViewSet
urls.py
1
2
3
4
5
6
7
|
url(r '^books/$' , views.BookViewSet.as_view({ "get" : "list" , "post" : "create" }),name = "book_list" ), url(r '^books/(?P<pk>\d+)$' , views.BookViewSet.as_view({ 'get' : 'retrieve' , 'put' : 'update' , 'patch' : 'partial_update' , 'delete' : 'destroy' }),name = "book_detail" ), |
views.py
1
2
3
4
|
from rest_framework import viewsets class BookViewSet(viewsets.ModelViewSet): queryset = models.Book.objects. all () serializer_class = serializer.BookSerializers |
示例
INSTALLED_APPS = [
....
'rest_framework',
]
settings.py
from django.db import models class Book(models.Model):
title=models.CharField(max_length=32)
price=models.IntegerField()
pub_date=models.DateField()
publish=models.ForeignKey("Publish",on_delete=models.CASCADE)
authors=models.ManyToManyField("Author")
def __str__(self):
return self.title class Publish(models.Model):
name=models.CharField(max_length=32)
email=models.EmailField()
def __str__(self):
return self.name class Author(models.Model):
name=models.CharField(max_length=32)
age=models.IntegerField()
def __str__(self):
return self.name
models.py
########### urls.py ##############
from django.contrib import admin
from django.urls import path,re_path,include urlpatterns = [
re_path("testrestfulframework/",include("testrestfulframework.urls")),
] ########### testrestfulframework/urls.py ############## from django.contrib import admin
from django.urls import path,re_path,include
from testrestfulframework import views urlpatterns = [
re_path(r'^books/$', views.BookViewSet.as_view(),name="book_list"),
re_path(r'^books/(?P<pk>\d+)$', views.BookDetailViewSet.as_view(),name="book_detail"),
re_path(r'^publishers/$', views.PublishViewSet.as_view(),name="publish_list"),
re_path(r'^publishers/(?P<pk>\d+)$', views.PublishDetailViewSet.as_view(),name="publish_detail"),
re_path(r'^authors/$', views.AuthorViewSet.as_view(), name="authorlist"),
re_path(r'^authors/(?P<pk>\d+)$', views.AuthorDetailViewSet.as_view(), name="author_detail"), # re_path(r'^books/$', views.BookViewSet.as_view(**{"get":"list","post":"create"}),name="book_list"),
# re_path(r'^books/(?P<pk>\d+)$', views.BookViewSet.as_view(**{'get': 'retrieve','put': 'update','patch': 'partial_update','delete': 'destroy'}),name="book_detail"),
]
urls.py
示例0 views的不同写法(以下三种写法等价)
from rest_framework.views import APIView
from rest_framework.response import Response
from django.shortcuts import HttpResponse
from rest_framework import mixins from .models import *
from rest_framework import generics
from rest_framework import serializers class BookSerializers(serializers.ModelSerializer):
class Meta:
model = Book
fields = "__all__"
# depth=1 class BookViewSet(APIView): def get(self,request,*args,**kwargs):
book_list=Book.objects.all()
bs=BookSerializers(book_list,many=True,context={"request":request})
return Response(bs.data) def post(self, request, *args, **kwargs): bs = BookSerializers(data=request.data, many=False,context={"request":request})
if bs.is_valid():
# print(bs.validated_data)
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) class BookDetailViewSet(APIView): def get(self,request,*args,**kwargs):
book_obj=Book.objects.filter(pk=kwargs["pk"]).first()
bs=BookSerializers(book_obj,context={"request":request})
return Response(bs.data) def put(self,request,*args,**kwargs):
book_obj=Book.objects.filter(pk=kwargs["pk"]).first()
bs=BookSerializers(book_obj,data=request.data,context={"request":request})
if bs.is_valid():
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) def patch(self,request,*args,**kwargs):
book_obj=Book.objects.filter(pk=kwargs["pk"]).first()
bs=BookSerializers(book_obj,data=request.data,context={"request":request},partial="partial")
if bs.is_valid():
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) def delete(self,request,*args,**kwargs):
# 这里是自己写的,没找到网上相关
book_obj=Book.objects.filter(pk=kwargs["pk"]).first() if book_obj:
book_obj.delete()
return Response("delete done")
else:
return Response("no such data")
一般写法
from .models import *
from rest_framework import mixins
from rest_framework import generics
from rest_framework import serializers class BookSerializers(serializers.ModelSerializer):
class Meta:
model = Book
fields = "__all__"
# depth=1 class BookViewSet(mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView): queryset = Book.objects.all()
serializer_class = BookSerializers def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs) def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs) class BookDetailViewSet(mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializers def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs) def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs) def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs) def patch(self,request,*args,**kwargs):
return self.partial_update(request,*args,**kwargs)
mixins类
from .models import *
from rest_framework import generics
from rest_framework import serializers class BookSerializers(serializers.ModelSerializer):
class Meta:
model = Book
fields = "__all__"
# depth=1 class BookViewSet(generics.ListCreateAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializers class BookDetailViewSet(generics.RetrieveUpdateDestroyAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializers
纯generics类
以上均试验成功。
示例1 get请求
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import *
from django.shortcuts import HttpResponse from rest_framework import serializers class BookSerializers(serializers.Serializer):
title=serializers.CharField(max_length=32)
price=serializers.IntegerField()
pub_date=serializers.DateField()
publish=serializers.CharField(source="publish.name")
#authors=serializers.CharField(source="authors.all")
authors=serializers.SerializerMethodField()
def get_authors(self,obj):
temp=[]
for author in obj.authors.all():
# temp.append(author.name)
# temp.append((author.name,author.age,author.id))
temp.append({"id":author.id,"name":author.name,"age":author.age})
return temp class BookViewSet(APIView): def get(self,request,*args,**kwargs):
book_list=Book.objects.all()
# 序列化方式1:
# from django.forms.models import model_to_dict
# data=[]
# for obj in book_list:
# data.append(model_to_dict(obj))
# print(data)
# return HttpResponse(data) # 序列化方式2:
# from django.core import serializers as dcs # 跟from rest_framework import serializers名字冲突了
# data=dcs.serialize("json",book_list)
# return HttpResponse(data) # 序列化方式3:
bs=BookSerializers(book_list,many=True)
return Response(bs.data) views.py
views.py --get请求
方式1:
方式2:
方式3:
示例2 post请求
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import *
from django.shortcuts import HttpResponse from rest_framework import serializers class BookSerializers(serializers.ModelSerializer):
class Meta:
model = Book
fields = "__all__"
# depth = 1 class BookViewSet(APIView): def get(self,request,*args,**kwargs):
book_list=Book.objects.all()
# 序列化方式1:
# from django.forms.models import model_to_dict
# data=[]
# for obj in book_list:
# data.append(model_to_dict(obj))
# print(data)
# return HttpResponse(data) # 序列化方式2:
# from django.core import serializers as dcs # 跟from rest_framework import serializers名字冲突了
# data=dcs.serialize("json",book_list)
# return HttpResponse(data) # 序列化方式3:
bs=BookSerializers(book_list,many=True)
return Response(bs.data) def post(self, request, *args, **kwargs): bs = BookSerializers(data=request.data, many=False)
if bs.is_valid():
# print(bs.validated_data)
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors)
veiws.py ——post请求
示例3 单条数据的get 和 put
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import *
from django.shortcuts import HttpResponse from rest_framework import serializers class BookSerializers(serializers.ModelSerializer):
class Meta:
model = Book
fields = "__all__"
# exclude = ['authors',]
# depth=1 # def create(self, validated_data):
# authors = validated_data.pop('authors')
# print(authors)
# obj = Book.objects.create(**validated_data)
# obj.authors.add(*authors)
# return obj class BookViewSet(APIView): def get(self,request,*args,**kwargs):
book_list=Book.objects.all()
# 序列化方式1:
# from django.forms.models import model_to_dict
# data=[]
# for obj in book_list:
# data.append(model_to_dict(obj))
# print(data)
# return HttpResponse(data) # 序列化方式2:
# from django.core import serializers as dcs # 跟from rest_framework import serializers名字冲突了
# data=dcs.serialize("json",book_list)
# return HttpResponse(data) # 序列化方式3:
bs=BookSerializers(book_list,many=True)
return Response(bs.data) def post(self, request, *args, **kwargs): bs = BookSerializers(data=request.data, many=False)
if bs.is_valid():
# print(bs.validated_data)
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) class BookDetailViewSet(APIView): def get(self,request,pk):
book_obj=Book.objects.filter(pk=pk).first()
bs=BookSerializers(book_obj)
return Response(bs.data) def put(self,request,pk):
book_obj=Book.objects.filter(pk=pk).first()
bs=BookSerializers(book_obj,data=request.data)
if bs.is_valid():
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors)
views.py --单条数据的get和put
示例4 外键_超链接
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import *
from django.shortcuts import HttpResponse from rest_framework import serializers class BookSerializers(serializers.ModelSerializer):
publish = serializers.HyperlinkedIdentityField(
view_name='publish_detail',
lookup_field="publish_id",
lookup_url_kwarg="pk") class Meta:
model = Book
fields = "__all__"
# depth=1 class PublshSerializers(serializers.ModelSerializer):
class Meta:
model = Publish
fields = "__all__"
# depth = 1 class AuthorSerializers(serializers.ModelSerializer): class Meta:
model = Author
fields = "__all__"
# depth = 1 class BookViewSet(APIView): def get(self,request,*args,**kwargs):
book_list=Book.objects.all()
# 序列化方式1:
# from django.forms.models import model_to_dict
# data=[]
# for obj in book_list:
# data.append(model_to_dict(obj))
# print(data)
# return HttpResponse(data) # 序列化方式2:
# from django.core import serializers as dcs # 跟from rest_framework import serializers名字冲突了
# data=dcs.serialize("json",book_list)
# return HttpResponse(data) # 序列化方式3:
# bs=BookSerializers(book_list,many=True)
bs=BookSerializers(book_list,many=True,context={"request":request})
return Response(bs.data) def post(self, request, *args, **kwargs): # bs = BookSerializers(data=request.data, many=False)
bs = BookSerializers(data=request.data, many=False,context={"request":request})
if bs.is_valid():
# print(bs.validated_data)
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) class BookDetailViewSet(APIView): def get(self,request,pk):
book_obj=Book.objects.filter(pk=pk).first()
# bs=BookSerializers(book_obj)
bs=BookSerializers(book_obj,context={"request":request})
return Response(bs.data) def put(self,request,pk):
book_obj=Book.objects.filter(pk=pk).first()
# bs=BookSerializers(book_obj,data=request.data)
bs=BookSerializers(book_obj,data=request.data,context={"request":request})
if bs.is_valid():
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) class PublishViewSet(APIView): def get(self,request,*args,**kwargs):
publish_list=Publish.objects.all()
bs=PublshSerializers(publish_list,many=True,context={'request': request})
return Response(bs.data) def post(self,request,*args,**kwargs): bs=PublshSerializers(data=request.data,many=False,context={'request': request})
if bs.is_valid():
# print(bs.validated_data)
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) class PublishDetailViewSet(APIView): def get(self,request,pk): publish_obj=Publish.objects.filter(pk=pk).first()
bs=PublshSerializers(publish_obj,context={'request': request})
return Response(bs.data) def put(self,request,pk):
publish_obj=Publish.objects.filter(pk=pk).first()
bs=PublshSerializers(publish_obj,data=request.data,context={'request': request})
if bs.is_valid():
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) class AuthorViewSet(APIView): def get(self,request,*args,**kwargs):
author_list=Author.objects.all()
bs=AuthorSerializers(author_list,many=True,context={'request': request})
return Response(bs.data) def post(self,request,*args,**kwargs): bs=AuthorSerializers(data=request.data,many=False,context={'request': request})
if bs.is_valid():
# print(bs.validated_data)
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors) class AuthorDetailViewSet(APIView): def get(self,request,pk): Author_obj=Author.objects.filter(pk=pk).first()
bs=AuthorSerializers(Author_obj,context={'request': request})
return Response(bs.data) def put(self,request,pk):
Author_obj=Author.objects.filter(pk=pk).first()
bs=AuthorSerializers(Author_obj,data=request.data,context={'request': request})
if bs.is_valid():
bs.save()
return Response(bs.data)
else:
return HttpResponse(bs.errors)
views.py --外键 超链接
暂时未找到多对多的超链接
示例5 使用封装
mixin类
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import *
from django.shortcuts import HttpResponse from rest_framework import serializers from rest_framework import mixins
from rest_framework import generics class BookSerializers(serializers.ModelSerializer):
publish = serializers.HyperlinkedIdentityField(
view_name='publish_detail',
lookup_field="publish_id",
lookup_url_kwarg="pk") class Meta:
model = Book
fields = "__all__"
# depth=1 class PublshSerializers(serializers.ModelSerializer):
class Meta:
model = Publish
fields = "__all__"
# depth = 1 class AuthorSerializers(serializers.ModelSerializer): class Meta:
model = Author
fields = "__all__"
# depth = 1 class BookViewSet(mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView): queryset = Book.objects.all()
serializer_class = BookSerializers def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs) def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs) class BookDetailViewSet(mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializers def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs) def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs) def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)
views.py --mixin类编写视图
generices包下面的类
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import *
from django.shortcuts import HttpResponse from rest_framework import serializers class BookSerializers(serializers.ModelSerializer):
publish = serializers.HyperlinkedIdentityField(
view_name='publish_detail',
lookup_field="publish_id",
lookup_url_kwarg="pk") class Meta:
model = Book
fields = "__all__"
# depth=1 class PublshSerializers(serializers.ModelSerializer):
class Meta:
model = Publish
fields = "__all__"
# depth = 1 class AuthorSerializers(serializers.ModelSerializer): class Meta:
model = Author
fields = "__all__"
# depth = 1 from rest_framework import mixins
from rest_framework import generics class BookViewSet(generics.ListCreateAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializers class BookDetailViewSet(generics.RetrieveUpdateDestroyAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializers class PublishViewSet(generics.ListCreateAPIView):
queryset = Publish.objects.all()
serializer_class = PublshSerializers class PublishDetailViewSet(generics.RetrieveUpdateDestroyAPIView):
queryset = Publish.objects.all()
serializer_class = PublshSerializers class AuthorViewSet(generics.ListCreateAPIView):
queryset = Author.objects.all()
serializer_class = AuthorSerializers class AuthorDetailViewSet(generics.RetrieveUpdateDestroyAPIView):
queryset = Author.objects.all()
serializer_class = AuthorSerializers
views.py --使用通用的基于类的视图
测试通过,与上类似,略,
继承viewsets包下的ModelViewSet
from .models import *
from rest_framework import serializers class BookSerializers(serializers.ModelSerializer):
class Meta:
model = Book
fields = "__all__"
# depth=1 from rest_framework import viewsets
class BookViewSet(viewsets.ModelViewSet):
queryset = Book.objects.all()
serializer_class = BookSerializers
views.py --使用ModelViewSet
from django.urls import path,re_path,include
from testrestfulframework import views urlpatterns = [
re_path(r'^books/$', views.BookViewSet.as_view({"get":"list","post":"create"}),name="book_list"),
re_path(r'^books/(?P<pk>\d+)$', views.BookViewSet.as_view({
'get': 'retrieve',
'put': 'update',
'patch': 'partial_update',
'delete': 'destroy'
}),name="book_detail"),
# re_path(r'^books/$', views.BookViewSet.as_view(),name="book_list"),
# re_path(r'^books/(?P<pk>\d+)$', views.BookDetailViewSet.as_view(),name="book_detail"),
]
urls.py
参考or转发
http://www.cnblogs.com/fu-yong/p/9052504.html
https://www.cnblogs.com/JetpropelledSnake/p/9397647.html
Django_rest_framework_基础的更多相关文章
- java基础集合经典训练题
第一题:要求产生10个随机的字符串,每一个字符串互相不重复,每一个字符串中组成的字符(a-zA-Z0-9)也不相同,每个字符串长度为10; 分析:*1.看到这个题目,或许你脑海中会想到很多方法,比如判 ...
- node-webkit 环境搭建与基础demo
首先去github上面下载(地址),具体更具自己的系统,我的是windows,这里只给出windows的做法 下载windows x64版本 下载之后解压,得到以下东西 为了方便,我们直接在这个目录中 ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- Golang, 以17个简短代码片段,切底弄懂 channel 基础
(原创出处为本博客:http://www.cnblogs.com/linguanh/) 前序: 因为打算自己搞个基于Golang的IM服务器,所以复习了下之前一直没怎么使用的协程.管道等高并发编程知识 ...
- [C#] C# 基础回顾 - 匿名方法
C# 基础回顾 - 匿名方法 目录 简介 匿名方法的参数使用范围 委托示例 简介 在 C# 2.0 之前的版本中,我们创建委托的唯一形式 -- 命名方法. 而 C# 2.0 -- 引进了匿名方法,在 ...
- HTTPS 互联网世界的安全基础
近一年公司在努力推进全站的 HTTPS 化,作为负责应用系统的我们,在配合这个趋势的过程中,顺便也就想去搞清楚 HTTP 后面的这个 S 到底是个什么含义?有什么作用?带来了哪些影响?毕竟以前也就只是 ...
- Swift与C#的基础语法比较
背景: 这两天不小心看了一下Swift的基础语法,感觉既然看了,还是写一下笔记,留个痕迹~ 总体而言,感觉Swift是一种前后端多种语言混合的产物~~~ 做为一名.NET阵营人士,少少多多总喜欢通过对 ...
- .NetCore MVC中的路由(1)路由配置基础
.NetCore MVC中的路由(1)路由配置基础 0x00 路由在MVC中起到的作用 前段时间一直忙于别的事情,终于搞定了继续学习.NetCore.这次学习的主题是MVC中的路由.路由是所有MVC框 ...
- .NET基础拾遗(5)多线程开发基础
Index : (1)类型语法.内存管理和垃圾回收基础 (2)面向对象的实现和异常的处理基础 (3)字符串.集合与流 (4)委托.事件.反射与特性 (5)多线程开发基础 (6)ADO.NET与数据库开 ...
随机推荐
- TortoiseGit需要重复填写用户名和密码的问题
命令行执行: git config --global credential.helper store 即可
- PAT乙级1001
https://pintia.cn/problem-sets/994805260223102976/problems/994805325918486528 #include<bits/stdc+ ...
- warning:ISO C90 forbids mixed declarations and code
warning:ISO C90 forbids mixed declarations and code 变量定义之前不论什么一条非变量定义的语句(重视:语句是会带分号的)都会引起这个警告! 将非变量的 ...
- CodeIgniter Doctrine2基本使用(一)(转)
CodeIgniter Doctrine2基本使用(一) 之前写了一篇文章叫作<CodeIgniter 3.0整合Doctrine2>里面介绍了一些简单的Doctrine2的用法,当然我也 ...
- python基础之import模块导入和包的调用
模块概念 在Python中,一个.py文件就称之为一个模块(Module).使用模块组织代码,最大的好处是大大提高了代码的可维护性 模块一共三种:python标准库.第三方模块.应用程序自定义模块. ...
- 【转】Win10/UWP新特性系列—Web
Internet Explorer Internet Explorer 在Windows 10 升级为Edge模式,是一种交互性和兼容性都很强的新型浏览器,该浏览器相比以前的版本更新了超过2000个操 ...
- c++ switch语句
一.认识switch格式 switch(表达式) { case 常量表达式: 语句1; break; case 常量表达式: 语句2; break; case 常量表达式: 语句3; break; . ...
- 【转载】COM 组件设计与应用(二)——GUID 和 接口
原文:http://vckbase.com/index.php/wv/1203.html COM 组件设计与应用 系列文章:http://vckbase.com/index.php/piwz?& ...
- 柯朗微积分与数学分析习题选解(1.1 节 a)
一直在读<陶哲轩实分析>,陶的书非常的严谨,环环相扣,但是也有个缺点就是计算性的例子和应用方面的例子太少了.所以就又找了本柯朗的<微积分与数学分析>搭配着看.柯朗的书的习题与陶 ...
- 2-[HTML]--介绍
1.HTML简介 HTML,全称是超文本标记语言(HyperText Markup Language),它是一种用于创建网页的标记语言.标记语言是一种将文本(Text)以及文本相关的其他信息结合起来, ...