unioslo/mreg

Django-rest-swagger broken after Django 3

Closed this issue ยท 7 comments

/docs/ produces:

'staticfiles' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log rest_framework static tz

The staticfiles and admin_static template tag libraries are removed.

https://docs.djangoproject.com/en/3.0/releases/3.0/

Django-rest-swagger is deprecated. We probably have to move to something else.

marcgibbons/django-rest-swagger#815

Angy commented

Doesn't work with Django 2.2.10 either

The fix is simple, navigate to index.html (AppData\Local\programs\python\python38\lib\site-packages\rest-framework-swagger\index.html)
change second line {% load staticfiles %}
to {% load static %}
Should then work

Update if you're still stumbling upon this error the above fix will only fix it locally, fixing this on a server is painful.
Instead, just use a completely different Swagger generator i suggest drf-yasg

@FairTraxx Thanks, I will take a look at drf-yasg.

The django-rest-swagger dependency was removed with #411.

The fix is simple, navigate to index.html ((localtion of ur pip package installation)\Lib\site-packages\rest_framework_swagger\templates\rest_framework_swagger\index.html)
change second line {% load staticfiles %}
to {% load static %}
Should then work

Another Fix i found useful is this.

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'libraries': {
'staticfiles': 'django.templatetags.static',
}
},
},
]

Include template.libraries as staticfiles so that you dont have to change the index.html inside env.