bootstrap-4django-formspython-3.7django-crispy-forms

ModuleNotFoundError: No module named 'crispy'


I want to use crispy-forms for making blog, so I tried to install crispy-forms in my code, but it's not working and shows error.

I did like below, and each results:

pip install django-crispy-forms

Result:

Requirement already satisfied: django-crispy-forms in /Users/eunwoo/PycharmProjects/PyShop/venv/lib/python3.8/site-packages (1.8.1)

pip3 install django-crispy-forms

Result:

Requirement already satisfied: django-crispy-forms in /Users/eunwoo/PycharmProjects/PyShop/venv/lib/python3.8/site-packages (1.8.1)

pip install -e git+git://github.com/maraujop/django-crispy-forms.git#egg=django-crispy-forms

Result:


Obtaining django-crispy-forms from git+git://github.com/maraujop/django-crispy-forms.git#egg=django-crispy-forms
  Cloning git://github.com/maraujop/django-crispy-forms.git to /Users/eunwoo/PycharmProjects/PyShop/venv/src/django-crispy-forms
Installing collected packages: django-crispy-forms
  Found existing installation: django-crispy-forms 1.8.1
    Uninstalling django-crispy-forms-1.8.1:
      Successfully uninstalled django-crispy-forms-1.8.1
  Running setup.py develop for django-crispy-forms
Successfully installed django-crispy-forms

But when I python3 manage.py runserver I got this error

~/PycharmProjects/django_project via PyShop took 26s 
īœ‘ ļ² python3 manage.py makemigratinos
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/eunwoo/PycharmProjects/PyShop/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/eunwoo/PycharmProjects/PyShop/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/Users/eunwoo/PycharmProjects/PyShop/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/eunwoo/PycharmProjects/PyShop/venv/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Users/eunwoo/PycharmProjects/PyShop/venv/lib/python3.8/site-packages/django/apps/config.py", line 116, in create
    mod = import_module(mod_path)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'crispy'

and setting.py

"""
Django settings for django_project project.

Generated by 'django-admin startproject' using Django 3.0.2.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '7sh#^-+*tczxfimk@+wq4s6jx$2(204&z9_d)mjomv1^y6644!'

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

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'blog.apps.BlogConfig',
    'users.apps.UsersConfig',
    'crispy.forms',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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 = 'django_project.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates/base')],
        '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 = 'django_project.wsgi.application'

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

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

# Password validation
# https://docs.djangoproject.com/en/3.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/3.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/3.0/howto/static-files/

STATIC_URL = '/static/'

# STATIC_ROOT = os.path.join(BASE_DIR, "static")
#
STATICFILES_DIRS = [
    "/Users/eunwoo/PycharmProjects/django_project/static"
    , ]

CRISPY_TEMPLATE_PACK = 'bootstrap4'

and base.html (which in templates/base/)

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
          integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="{% static 'blog/main.css' %}">

    <title>
        {% block title %}
        {% endblock title %}
    </title>

</head>
<body>
<header class="site-header">
    <nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
        <div class="container">
            <a class="navbar-brand mr-4" href="{% url 'blog-home' %}">CHOs Blog</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle"
                    aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarToggle">
                <div class="navbar-nav mr-auto">
                    <a class="nav-item nav-link" href="{% url 'blog-home' %}">Home</a>
                    <a class="nav-item nav-link" href="{% url 'blog-about' %}">About</a>
                </div>
                <!-- Navbar Right Side -->
                <div class="navbar-nav">
                    <a class="nav-item nav-link" href="#">Login</a>
                    <a class="nav-item nav-link" href="#">Register</a>
                </div>
            </div>
        </div>
    </nav>
</header>


<main role="main" class="container">
    <div class="row">
        <div class="col-md-8">
            {% if messages %}
                {% for message in messages %}
                <div class="alert alert-{{ message.tags }}">
                   ** {{ message }} **
                </div>
                {% endfor %}
            {% endif %}
            {% block content %}{% endblock %}
        </div>
        <div class="col-md-4">
            <div class="content-section">
                <h3>Our Sidebar</h3>
                <p class='text-muted'>You can put any information here you'd like.
                <ul class="list-group">
                    <li class="list-group-item list-group-item-light">Latest Posts</li>
                    <li class="list-group-item list-group-item-light">Announcements</li>
                    <li class="list-group-item list-group-item-light">Calendars</li>
                    <li class="list-group-item list-group-item-light">etc</li>
                </ul>
                </p>
            </div>
        </div>
    </div>
</main>


<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
        integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
        crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
        integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
        crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
        integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
        crossorigin="anonymous"></script>
</body>
</html>

and register.html (which include crispy.forms)

{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
    <form method="POST">
        {% csrf_token %}
        <fieldset class="form-group">
            <legend class="border-bottom mb-4">Join Today Jin!</legend>
            {{ form|crispy }}
        </fieldset>
        <button class="btn btn-outline-info" type="submit">
            Sign Up
        </button>
    </form>
    <div class="border-top pt-3">
        <small class="text-muted">
            Already Have An Account?
            <a href="#" class="ml-2">SIGN IN</a>
        </small>
    </div>

</div>
{% endblock content %}

So what command do I need to do?


Solution

  • You should be using crispy_forms in your INSTALLED_APPS, not cripsy.forms.