尝试在 django 2.2.4 中为 django rest 框架自动生成 API 文档时出现此错误,从我在日志中看到的内容来看,这与 {% load staticfiles %} 的弃用有关
templateSyntaxError at /
'staticfiles' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_urls
cache
countries
i18n
l10n
log
phone
rest_framework
static
tz
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 3.0
Exception Type: TemplateSyntaxError
Exception Value:
'staticfiles' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_urls
cache
countries
i18n
l10n
log
phone
rest_framework
static
tz
{% load i18n %}
2 {% load staticfiles %}
3 <!DOCTYPE html>
4 <html lang="en">
5 <head>
6 <meta charset="UTF-8">
7 <title>Swagger UI</title>
8 <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
9 <link href="{% static 'rest_framework_swagger/bundles/vendors.bundle.css' %}" rel="stylesheet" type="text/css">
10 <link href="{% static 'rest_framework_swagger/bundles/app.bundle.css' %}" rel="stylesheet" type="text/css">
11 {% block extra_styles %}
12 {# -- Add any additional CSS scripts here -- #}
我的 urls 文件,它的格式与 django_rest_swagger 文档中的格式相同:
from django.contrib import admin
from django.urls import path, include
from rest_framework_swagger.views import get_swagger_view
schema_view = get_swagger_view(title='My API')
urlpatterns = [
path('admin/', admin.site.urls),
path('api/user/', include('user.urls'),
path('', schema_view)]