django 模板呈现过程中出错,无效筛选器:'bootstrap'

uidvcgyl  于 2023-08-08  发布在  Go
关注(0)|答案(2)|浏览(102)

我在ubuntu20.04操作系统上使用django3.0。我创建了一个工作门户项目,但是当我运行代码时。它会给出类似- Invalid filter的错误:'bootstrap'这里的代码如下- templates/accounts/login.html:-

{% extends 'base.html' %}
{% load static %}
{% load bootstrap %}

{% block content %}
    <section class="home-section section-hero inner-page overlay bg-image"
             style="background-image: url('images/hero_1.jpg');" id="home-section">
        <div class="container">
            <div class="row align-items-center justify-content-center">
                <div class="col-md-12">
                    <div class="mb-5 text-center">

                        <h2 class="text-white font-weight-bold">LOGIN</h2>

                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="site-section" id="next-section">
        <div class="container">
            <div class="row justify-content-center">

                <div class="col-lg-5 mb-5 mb-lg-0">
                    <p>Already have your account?</p>
                    <form action="" method="POST">{% csrf_token %}

                        {{ form|bootstrap }}

                        <div class="row form-group">
                            <div class="col-md-12">
                                <input type="submit" value="Login" class="btn btn-primary btn-md text-white">
                            </div>
                        </div>

                    </form>
                </div>

            </div>
        </div>
    </section>
    <section class="py-5 bg-image overlay-primary fixed overlay">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <h2 class="text-white">Looking For A Job?</h2>
                    <p class="mb-0 text-white lead">
Lorem ipsum dolor sit amet consectetur rebates the times of the
                        win
                        impedes.</p>
                    </p>
                </div>
                <div class="col-md-3 ml-auto">
                    <a href="{% url 'accounts:signup' %}" class="btn btn-warning btn-block btn-lg">Sign Up</a>
                </div>
            </div>
        </div>
    </section>

{% endblock %}

字符串

无效的过滤器:'bootstrap'

{{表单|bootstrap(引导)
settings.py:-

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', '4^fw*wh7gw+ek$ipnlp+#bf1py$$d2vobjddsdfi-7!&5(9v1ifzuu3')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Email Settings

SEND_GRID_API_KEY = ''
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = '' #sendgrid email
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'dineshsharma201008@gmail.com' #sendgrig email
ACCOUNT_EMAIL_SUBJECT_PREFIX = 'Contact email from CAREERS'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'accounts',
    'jobs',
     'bootstrap4',

    'crispy_forms',
    'django_forms_bootstrap',
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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',
]

ROOT_URLCONF = 'job_portal.urls'

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',
            ],
        },
    },
]

WSGI_APPLICATION = 'job_portal.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

import dj_database_url
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
#DATABASES['default']['CONN_MAX_AGE'] = 500

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'


有什么不对或缺少什么!!请帮助我是新的django.谢啦,谢啦

ev7lccsx

ev7lccsx1#

简单打字你的load调用应该是'bootstrap4',正如这里所说的:https://django-bootstrap4.readthedocs.io/en/latest/quickstart.html

s5a0g9ez

s5a0g9ez2#

将'bootstrap'替换为'bootstrap 4' {{ form| bootstrap }}无效筛选器:'bootstrap'

相关问题