簡體   English   中英

Django 蜜罐錯誤模板定制

[英]Django honeypot error template customization

I am using Django honeypot ( https://github.com/jamesturk/django-honeypot ) and was wondering how to customize the honeypot_error.html page ( https://github.com/jamesturk/django-honeypot/blob/master/ honeypot/templates/honeypot/honeypot_error.html ),當蜜罐檢測被觸發時執行。 謝謝!!

如果您的項目中有honeypot_error.html和相同的結構化路徑templates/honeypot/honeypot_error.html ,它將把您的頁面作為默認頁面。 (看重點: 這里

示例:package x 在templates/myapp/toto.html中定義一個名為toto.html的模板

在您的應用程序中,在templates/myapp/toto.html toto.html添加自定義的 toto.html

打電話時

python manage.py collectstatic

它將獲取您的模板,而不是 myapp 默認提供的模板

我無法評論 MSR974 的回答,所以:

來自 Django 關於覆蓋模板的文檔:

from pathlib import Path

BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

INSTALLED_APPS = [
    ...,
    'blog',
    ...,
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        'APP_DIRS': True,
        ...
    },
]

注意:“如果您的應用程序和項目模板目錄都包含覆蓋,則默認的 Django 模板加載器將首先嘗試從項目級目錄加載模板。換句話說,在 APP_DIRS 之前搜索 DIRS 。”

在閱讀示例時,請記住 APP 和 PROJECT 模板之間的區別,並確保您已根據所選策略配置了 SETTINGS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM