Give Your Django APIs A User Interface Without Coding

Vikas Gautam
Geek Culture
Published in
2 min readJul 23, 2021

--

Django Rest APIs access using Swagger UI

Swagger UI

Django is the most popular Python framework for building web applications, which are scalable and can easily handle a large number of users. For such big applications usually, the backend part having APIs is developed first, and then comes the UI part and to access the backend APIs having a UI is always a good idea rather than using CURL commands.

Swagger provides UI to access backend APIs, this UI is good for non-technical persons and frontend developers for accessing and testing backend APIs. The main advantage of Swagger UI is that

  1. It does not need much time of developers to develop
  2. And this UI is accessible to anyone who can access the Django web application.
  3. Also adding headers, query, and body parameters are very on Swagger UI.
  4. Each API has its description so the user does not need to check a document or ask the developer how to use the API.

Now Let’s get an exiting Django web application and integrate Swagger UI

Get existing Django web application

  1. To know about how to create CRUD Rest APIs in Django check out this blog https://vgautam99.medium.com/1bb174596ada?source=friends_link&sk=83efb7a3bdbd05e3f5188b4be02d97e4
  2. Create Virtual Environment and Activate it

Install: https://pypi.org/project/virtualenv/

virtualenv venv

Windows

cd venv/Scripts
activate

Linux

cd venv/bin
source activate

Install Requirements

pip install -r requirements.txt
  1. Installation
pip install -U drf-yasg

2. Integrate with Django Web Application

Open DjangoSwagger/settings.py file and inside INSTALLED_APPS paste below lines

Note: Make sure that there is only one ‘django.contrib.staticfiles’ inside INSTALLED_APPS

settings.py

Open DjangoSwagger/urls.py and paste these lines

urls.py

3. Run Django Server And check Swagger UI

cd SwaggerDjango && python manage.py runserver

Now you can check Swagger UI at http://127.0.0.1:8000/swagger/

Swagger UI

--

--