django-rest-swagger | Swagger Documentation Generator for Django REST Framework | REST library
kandi X-RAY | django-rest-swagger Summary
kandi X-RAY | django-rest-swagger Summary
This project is no longer being maintained. Please consider drf-yasg as an alternative/successor. I haven't personally used it, but it looks feature-complete and is actively maintained.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Render the data
- Return the UI settings
- Set renderer context
- Get auth URLs
- Render data
- Get customizations
- Generate a JSON representation of a document
- Create a new model
- Highlight the snippet
- Return a Swagger view
django-rest-swagger Key Features
django-rest-swagger Examples and Code Snippets
$ pip install django-rest-swagger
# in settings.py
# Application definition
REST_FRAMEWORK_APPS = [
'rest_framework', #
'rest_framework.authtoken', # 认证应用
'rest_framework_swagger', # API文档应用 ==>用于生成文档的应用
]
CUSTOM_APPS = [
.
from rest_framework.schemas import get_schema_view
from rest_framework_swagger.renderers import OpenAPIRenderer, SwaggerUIRenderer
schema_view = get_schema_view(
title='Example API',
renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer]
)
u
>>> b'p\x00y\x00t\x00z\x00=\x00=\x002\x000\x001\x008\x00.\x005\x00\r\x00'.decode('utf-16')
'pytz==2018.5\r'
with open('requirements.txt', 'rb') as source_file:
contents = source_file.read()
with open(
from rest_framework_swagger import renderers
from rest_framework.decorators import api_view, renderer_classes
@api_view(['GET', 'POST'])
@renderer_classes([renderers.OpenAPIRenderer, renderers.SwaggerUIRenderer])
def app_info(request):
from rest_framework.generics import ListCreateAPIView
class TechnologyViewSet(ListCreateAPIView):
queryset = Technology.objects.all()
serializer_class = TechnologySerializer
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'd
INSTALLED_APPS = [
...
'rest_framework_swagger',
]
class CustomProfileSchema(AutoSchema):
manual_fields = [] # common fields
def get_manual_fields(self, path, method):
custom_fields = []
if method.lower() == "get":
custom_fields = [
cor
REST_FRAMEWORK = {
# ...
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.AllowAny',
),
}
Community Discussions
Trending Discussions on django-rest-swagger
QUESTION
previously in Django 1.11, I'ved defined Django REST API in this way:
in url.py
...ANSWER
Answered 2021-Jan-31 at 11:48As you said django-rest-swagger is deprecated.
That's why it is recommended to use drf-yasg.
QUESTION
I am using Django REST Framework to deploy on Google App Engine and my requirements.txt
file is as follows:
ANSWER
Answered 2018-Dec-03 at 16:30It looks like your requirements.txt
file is UTF-16 encoded:
QUESTION
Using django-rest-framework-json-api
I am able to create API end points that work as described within the documentation. Attempted to provide API documentation using django-rest-swagger
is not so easy.
1: Swagger uses media_type = 'application/json'
which is not supported in the JSON API. To get around this I created a second render class (renderer_classes
) that sub classes the JSON API JSONRenderer
and forces the media type.
Now the end point supports application/json
and application/vnd.api+json
and swagger is happy to render in JSON API document structure. Aware that the generated curl requests have none a standard JSON API header.
2: Swagger has the same issue with the parser. While the work out from issue 1 does work there is a secondary challenge. Swagger renders a flat dictionary of field names which is not JSON API and ultimately is requested by DRF.
Is it possible to get swagger to parse in JSON API? At the moment Swagger is not working for PUT or POST.
...ANSWER
Answered 2019-Apr-26 at 00:29Answering my own question here so that others can gain value from what was learnt. We never found a solution to this issue and we did not have the time available to contribute to this project. In general the project also appears to be struggling, maybe due to people like us not contributing...
An alternative project drf-yasg
has now emerged, which did not exist at the time of this original posting. drf-yasg
was relatively easy to deploy and solved all of our issues so we have now migrated to this project instead.
So if you a looking for swagger api documentation for JSON API endpoints created within DRF, then I would suggest drf-yasg
.
At the time of writing JSON API is not supported out of the box, but there is sample code to get it up and running relatively easily. With this change in place, all of the endpoints will be auto documented.
This Github Gist that contains the code from our app, hope that this helps you out until this feature is fully developed.
QUESTION
I am using Docker
to deploy Python2.7
application with Django1.8
.
I am facing some issue from last two days and I found error as below.
Docker Image: python:2.7-slim-buster
Error:
...ANSWER
Answered 2020-Apr-02 at 05:13Django-appconf version 1.0.4 only supports Django 1.11 and up and Python 3.5 and up. (https://github.com/django-compressor/django-appconf/blob/v1.0.4/setup.py). You need to downgrade to at least version 1.0.2 (supports Python 2.6+, doesn't say which django version: https://github.com/django-compressor/django-appconf/blob/v1.0.2/setup.py)
QUESTION
I went through Django REST Swagger 2.1.2 documentation. When I tried with class based views, it was working fine.
But i did not find any reference on how to enable swagger for function based views as shown below:
...ANSWER
Answered 2017-May-02 at 09:40i am not fammiliar with swagger,but you may try to use the decorator in this way:
QUESTION
I have a Django==2.2.3
app with djangorestframework==3.9.4
and django-rest-swagger==2.2.0
. I wanted to have a single source of truth (for data validation as well as api-docs) for my api endpoints. I have a JSON that looks something like this
ANSWER
Answered 2020-Mar-06 at 17:32You could define it in the parent's __new__
method.
Here is a simple example of how you can override it.
QUESTION
I am trying to integrate swagger 2.0 with existing DRF application but it gives following error in browser after runningpython manage.py runserver
:
TemplateDoesNotExist at /swagger rest_framework_swagger/index.html Request Method: GET Request URL: http://127.0.0.1:8000/swagger Django Version: 1.10 Exception Type: TemplateDoesNotExist Exception Value: rest_framework_swagger/index.html Exception Location: C:\Users\MHAZIQ~1\Desktop\Tkxel\mmg-git\venv\lib\site-packages\django\template\loader.py in get_template, line 25
I have added following lines in views.py:
from rest_framework_swagger.views import get_swagger_view
schema_view = get_swagger_view(title='Pastebin API')
And I have added following lines in urls.py:
url(r'^swagger', views.schema_view),
I ve tried applying following solution: TemplateDoesNotExist at /docs/ rest_framework_swagger/index.html
but it didnot solve my problem, Can anyone please help me in this regard?
...ANSWER
Answered 2017-Apr-20 at 08:07After several hours of research I have found the problem with my code, as I was adding swagger into an existing project, it didnt have following parameters in settings.py:
QUESTION
On my MacBook (version 10.14.6) I am succesfully running a Django application including TensorFlow and tf-sentencepiece (in particular to use the universal sentence encoder model). When I perform a pipenv lock -r > requirements.txt
I get the following required packages:
ANSWER
Answered 2020-Jan-09 at 09:54I have no skills in Django, but it seems that tensorflow is trying to find a package (with a strange name) and failing.
I'd first suggest to try and fix your docker container setup, and check that pipenv lock -r
yield the same result inside and outside your container.
1) as you said in the commentaries, on the host pc
QUESTION
I have this function-based view with django-rest-swagger decorated. However, I can't find place in UI that allow me to post the payload (request.body).
I saw a couple solutions about doing it with class-based view, but I was wondering if there is a way to do it with function-based view.
Thank you in advance!
...ANSWER
Answered 2019-Oct-21 at 02:31I am gonna answer my question since the django-rest-swagger was deprecated in June 2019 and I just found out 2 feasible solutions.
First one will change the UI globally.
In ping.views
(or any other location you wish) add following class.
QUESTION
I am new to Django. I am using Ubuntu, Apache, and virtualenv. I am running Ubuntu on DigitalOcean. I am trying to use Django and React together. So I downloaded djangorestframework. But when I run the server, I encountered this problem.
...ANSWER
Answered 2019-May-16 at 02:59It seems to me that you're trying to run this with a virtual environment called new_app
activated while Django REST Framework is installed globally.
You have to ways for solving this:
Run
pip install djangorestframework
(and any other you want or need) with thenew_app
environment being active. Note there is no sudo hereRun your development server with no virtual env active.
Of course, number one is the preferred way. Good luck!
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install django-rest-swagger
pip install django-rest-swagger
Add rest_framework_swagger to your INSTALLED_APPS setting: INSTALLED_APPS = ( ... 'rest_framework_swagger', )
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page