1
1

More than 3 years have passed since last update.

Django 3.0 でDjango REST Swaggerを使用すると発生するエラーの解消

Last updated at Posted at 2020-03-10

概要

Django 3.0 で、Django REST Swaggerを使用すると発生するエラーの解消

環境

エラーメッセージ

http://localhost:8000/swagger/ にアクセスすると下記のエラーが発生する

django.template.exceptions.TemplateSyntaxError: '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

解消方法

# swagger のhtmlファイルを編集
$ sudo vim /usr/local/lib/python3.6/site-packages/rest_framework_swagger/templates/rest_framework_swagger/index.html

もしswaggerのファイルパスがわからない場合は、grepで調べる
$ sudo grep -rl "staticfiles" /usr/local/lib

Before:

{% load staticfiles %}

After:
2行目を下記の内容に編集

{% load static %}

再度、 http://localhost:8000/swagger/ にアクセスするとつながる。
Django3.0では、'staticfiles' が削除されていることが原因。

公式ドキュメント
https://docs.djangoproject.com/en/dev/releases/3.0/#features-removed-in-3-0

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1