Django的templates在被继承时无法导入静态文件

    技术2022-07-10  101

    {%load static%} 无法被{%extends ***%}继承的解决方法,在settings.py里加入: ‘builtins’:[‘django.templatetags.static’]

    具体代码如下:

    TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(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', ], 'builtins':['django.templatetags.static']#新增 }, }, ]
    Processed: 0.013, SQL: 9