Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Python 100 Days | 135,076 | a month ago | 682 | Python | ||||||
Python - 100天从新手到大师 | ||||||||||
Django Rest Framework | 25,666 | 24,595 | 1,508 | a day ago | 134 | December 15, 2021 | 132 | other | Python | |
Web APIs for Django. 🎸 | ||||||||||
Awesome Django | 7,045 | 6 days ago | 2 | cc0-1.0 | HTML | |||||
A curated list of awesome things related to Django | ||||||||||
Drf Yasg | 3,092 | 290 | 76 | 19 days ago | 59 | October 25, 2020 | 235 | other | Python | |
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code. | ||||||||||
Django Rest Swagger | 2,516 | 2,031 | 41 | 3 years ago | 50 | April 30, 2018 | 168 | bsd-2-clause | Python | |
Swagger Documentation Generator for Django REST Framework: deprecated | ||||||||||
Django Rest Auth | 2,331 | 1,109 | 24 | 10 months ago | 25 | April 01, 2019 | 234 | mit | Python | |
This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON) | ||||||||||
Djoser | 2,288 | 212 | 5 | 11 days ago | 48 | October 30, 2020 | 166 | mit | Python | |
REST implementation of Django authentication system. | ||||||||||
Drf Nested Routers | 1,487 | 621 | 29 | 13 days ago | 19 | October 15, 2021 | 46 | apache-2.0 | Python | |
Nested Routers for Django Rest Framework | ||||||||||
Cookiecutter Django Rest | 1,405 | 4 days ago | 4 | mit | Python | |||||
Build best practiced apis fast with Python3 | ||||||||||
Drf Extensions | 1,371 | 323 | 14 | 9 days ago | 16 | July 30, 2021 | 75 | mit | Python | |
DRF-extensions is a collection of custom extensions for Django REST Framework |
Install using pip:
pip install django_restframework_apiview
Add 'apiview' to your INSTALLED_APPS setting:
INSTALLED_APPS = ( ... 'apiview', )
JSONP Renderer And debug apiview with paramslist:
REST_FRAMEWORK = { ... 'DEFAULT_RENDERER_CLASSES': [ ... 'apiview.renderers.JSONPRenderer', ], } if DEBUG: REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES'].append('apiview.renderers.BrowsableAPIRenderer')
Add error code to settings.py:
ERROR_CODE_DEFINE = ( ('ERR_AUTH_NOLOGIN', 10001, 'No login'), ('ERR_AUTH_USER_EXISTS', 10002, 'User name has exists'), ('ERR_AUTH_USER_NOT_EXISTS', 10003, 'User not exists'), ('ERR_AUTH_PASSWORD', 10005, 'Password error'), )
edit myapp/views.py:
#! usr/bin/env python # encoding: utf-8 from __future__ import absolute_import, unicode_literals from django.db import IntegrityError, transaction from django.contrib.auth import authenticate, login from django.contrib.auth.models import User from apiview.err_code import ErrCode from apiview.exceptions import CustomError from apiview.view import APIView from apiview.views import ViewSite from apiview.views import fields site = ViewSite(name='base', app_name='base') class APIBase(APIView): class Meta: path = '/' param_fields = ( ('channel', fields.CharField(help_text='App Channel', required=False)), ('version', fields.CharField(help_text='App Version', required=False)), ) class UserAPIBase(APIBase): def check_user_permission(self, request): user = request.user if not user.is_authenticated() or not isinstance(user, User): raise CustomError(ErrCode.ERR_AUTH_NOLOGIN) def view(self, request, *args, **kwargs): self.check_user_permission(request) return super(APIBase, self).view(request, *args, **kwargs) class Meta: path = '/user' @site class Login(APIBase): name = '' def get_context(self, request, *args, **kwargs): user = authenticate(username=request.params.username, password=request.params.password) if user is None: raise CustomError(ErrCode.ERR_AUTH_PASSWORD) login(request, user) return self.get_default_context(user_info={'username':request.user.username, 'email':request.user.email}) class Meta: path = 'user/login' param_fields = ( ('username', fields.CharField(help_text='')), ('password', fields.CharField(help_text='')), ) @site class Register(APIBase): name = '' def get_context(self, request, *args, **kwargs): try: user = User.objects.create_user(request.params.username, request.params.email, request.params.password) except IntegrityError: raise CustomError(ErrCode.ERR_AUTH_USER_EXISTS) return self.get_default_context() class Meta: path = 'user/register' param_fields = ( ('username', fields.RegexField(help_text='', regex=r'^[a-zA-Z0-9_]{3,10}$')), ('password', fields.CharField(help_text='')), ('email', fields.EmailField(help_text='Email')), ) @site class Info(UserAPIBase): name = '' def get_context(self, request, *args, **kwargs): user_info = {'username':request.user.username, 'email':request.user.email} return self.get_default_context(user_info=user_info) @site class Logout(UserAPIBase): name = '' def get_context(self, request, *args, **kwargs): logout(request) return self.get_default_context() urlpatterns = site.urlpatterns
add to urls.py end:
urlpatterns.append(url(r'^test/', include("myapp.views")))
run example:
git clone https://github.com/007gzs/django_restframework_apiview.git cd django_restframework_apiview/example pip install -r requirements.txt python manage.py makemigrations python manage.py migrate python manage.py runserver open http://127.0.0.1:8000/example.html in browser