[Django]-Django returns 'TemplateDoesNotExist' when using Crispy Forms

66👍

As of django-crispy-forms 2.0 the template packs are now in separate packages.

You will need to pip install crispy-bootstrap4 and add crispy_bootstrap4 to your list of INSTALLED_APPS.

15👍

if you need to use bootstrap4

  1. pip install django-crispy-forms
  2. pip install crispy-bootstrap4

inside settings.py in the main app add
INSTALLED_APPS = [ ... 'crispy_forms', 'crispy_bootstrap4', ... ]
and CRISPY_TEMPLATE_PACK = 'bootstrap4'

inside your_html.html file add
{% load crispy_forms_tags %} and you can use cripy_forms as you like

1👍

  1. Run this command:

    pip install django-crispy-forms
    
  2. Go to settings.py and add this in the installed apps (don’t forget the comma):

    "crispy_forms",
    "crispy_bootstrap4"
    
  3. Add this after the installed apps (here there’s no need for a comma):

    CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
    CRISPY_TEMPLATE_PACK = 'bootstrap4'
    
  4. Go to the html page where you want to add the crispy form and add this in the head section:

    {% load crispy_forms_tags %}
    
  5. Finally add this to the body section:

    {{form|crispy_field}} 
    

0👍

I faced same issue and got solution. This is because you are using django-crispy-forms==2.0 and your project is not compatible with this version. also this django-crispy-forms==2.0 not support bootstrap4.

SOLUTION:
so install packages with below mention version:
(make sure python version > 3.7)

  • pip3 install Django==4.1.6
  • pip3 install django-allauth==0.52.0
  • pip3 install django-crispy-forms==1.14.0 # version <=1.70
  • pip3 install django-embed-video

Leave a comment