小编Roh*_*hit的帖子

Django Message框架未在模板中显示消息

这是我的设置文件

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = (
       "django.core.context_processors.request",
       "django.core.context_processors.media",
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'h^@hi8e&q4e#h!j4v$x+@y2ngs&3&*o%!u8pi(vp3h8n&0$*a)'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (

   'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
Run Code Online (Sandbox Code Playgroud)

在模板中,我添加了以下代码以显示消息

{% if messages %}
<ul class="messages">
    {% for message in messages %}
    <li{% if message.tags %} class="{{ message.tags }}"{% endif …
Run Code Online (Sandbox Code Playgroud)

python django

2
推荐指数
1
解决办法
2437
查看次数

标签 统计

django ×1

python ×1