[Fixed]-Django_rest_swagger โ€“ 'staticfiles' is not a registered tag library. Must be one of:

32๐Ÿ‘

The problem is that staticfiles template tag was deprecated in Django 2.2 and is finally removed in Django 3.0

The djagno-rest-swagger package itself is deprecated and is no longer maintained.

Their GitHub repo recommends something like drf-yasg

19๐Ÿ‘

The library is deprecated

Quick fix(at your own risk): go to site-packages/rest_framework_swagger/templates/rest_framework_swagger/index.html

The line with {% load staticfiles %} (line 2) should be {% load static %}. You can edit it manually

๐Ÿ‘คkayondo terry

6๐Ÿ‘

You can also create a staticfiles.py in the templatetags folder of your app and then paste this code:

from django import template
from django.templatetags.static import (do_static as _do_static,static as _static,)

register = template.Library()

def static(path):
    return _static(path)

@register.tag('static')
def do_static(parser, token):
    return _do_static(parser, token)'

into the file.

But make sure that the your app comes before rest_framework_swagger in the app list of your settings.py.

๐Ÿ‘คnafiu

2๐Ÿ‘

The staticfiles template is deprecated in Django 2.2 and removed in Django 3.

We need to override the rest_framework_swagger/index.html.

Go to site-packages/rest_framework_swagger/templates/rest_framework_swagger

Copy the rest_framework_swagger folder and paste it in your own templates folder

Then replace the line 2 with {% load static %} in index.html

Hope it works !!

๐Ÿ‘คMuthu Kumar

1๐Ÿ‘

I found out that the django-rest-swagger Module is not available in django 3.0 or more since the template static label is removed.

Please use other swagger packages, such as drf-yasg

๐Ÿ‘คIbrahim

0๐Ÿ‘

To get around this:

  • navigate to your installation path of rest_framework_swagger, for me itโ€™s env\Lib\site-packages\rest_framework_swagger
  • goto templates/rest_framework_swagger folder and change staticfile to static in your index.html

This is because {% load staticfiles %} and {% load admin_static %} were deprecated in Django 2.1, and removed in Django 3.0.

This work around solution is what you can use till we get it updated in rest_framework_swagger app.

๐Ÿ‘ค1UC1F3R616

0๐Ÿ‘

The django-rest-framework is using the Template Tag staticfiles which was used in Django 2. It was been dropped in Django 3.0, while the django-rest-frame repo is not while update. It was deprecated in 2019. I whould suggest using drf-yasg from
https://github.com/axnsan12/drf-yasg

It preforms a similar function, to provide API docs automatically using swapper. Iโ€™ve used it and it seems good enough.

๐Ÿ‘คahsan mukhtar

0๐Ÿ‘

https://github.com/axnsan12/drf-yasg#quickstart

In settings.py:

INSTALLED_APPS = [
   ...
   'django.contrib.staticfiles',  # required for serving swagger ui's css/js files
   ...
]
๐Ÿ‘คkrzyzak

Leave a comment