Django Rest API – Browsable API – Part4

This is one the exciting features of DRF let’s see what it is.

To get start we need to install few packages

pip install djangorestframework
pip install markdown       # Markdown support for the browsable API.
pip install django-filter  # Filtering support

Once done in the settings.py file add this

INSTALLED_APPS = (
    ...
    'rest_framework',
)

and the main urls.py file

from django.contrib import admin
from django.urls import path, include, re_path as url

urlpatterns = [
    path('admin/', admin.site.urls),
    url(r'^', include('todo.urls')),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

Notice how i removed “^todo/’ from our urls.py. This is required i.e “url(r'^’, include(‘todo.urls’)),” without this for me browsable api were not showing up.

Once this is done, restart server and open http://127.0.0.1:8000/ in your browser directly. It will ask for login. If you don’t remember login create one using https://stackoverflow.com/a/18504852

Then you should see this

This is great! We have full api documentation created for us and we can easily share with frontend dev’s using this.

Also click on individual api to see further drill down.

Here we see a form to add data and play around with the api’s we have.

and also if you deploy the django app on server and Css does not render on admin panel and browsable api page do the following step

install dj_static with
pip install dj-static

then in settings.py file add

STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

then finally in your wsgi.py file write this

from dj_static import Cling

application = Cling(your_application_name())
excellence-social-linkdin
excellence-social-facebook
excellence-social-instagram
excellence-social-skype