【问题标题】:Why I can't customize templates in Django-Oscar?为什么我不能在 Django-Oscar 中自定义模板?
【发布时间】:2020-10-20 15:14:13
【问题描述】:

我正在尝试按照文档自定义基本模板。但是模板没有以任何方式响应我的更改...我做错了什么?

我的模板路径来自location():

.../django_shop/frobshop/frobshop/templates

我的项目结构:

我的设置:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            location('templates')
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.request',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.contrib.messages.context_processors.messages',

                # Oscar specific

                'oscar.apps.search.context_processors.search_form',
                'oscar.apps.communication.notifications.context_processors.notifications',
                'oscar.apps.checkout.context_processors.checkout',
                'oscar.core.context_processors.metadata',
            ],
            'debug': DEBUG,
        }
    }
]

我的 base.html:

{% extends 'oscar/base.html' %}

{% load i18n %}

{% block title %}
{% trans 'test title' %}
{% endblock %}
test

【问题讨论】:

    标签: django django-oscar


    【解决方案1】:

    您的 base.html 位于错误的位置 - 它需要位于 frobshop/templates/oscar/base.html 而不是 frobshop/templates/base.html

    Oscar 的所有模板都以 oscar/ 前缀命名 - 所以要覆盖它们,您必须这样做。

    【讨论】:

    • 感谢您的回答。在我的配置中,我必须将 oscar 文件夹添加到模板中。你救了我的神经)我的路:frobshop/frobshop/templates/oscar/base.html
    • 您只需将项目复制到文件夹中(正如他们在上面的答案中所写的那样)并且不要在模板本身中写入 {% extends 'oscar/base.html' %}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    相关资源
    最近更新 更多