Debug School

rakesh kumar
rakesh kumar

Posted on

Django returns 'TemplateDoesNotExist' when using Crispy Forms

Using Crispy Forms with Django, I can only get a TemplateDoesNotExist error when using any feature of Crispy Forms.

settings.py

Using Crispy Forms with Django, I can only get a TemplateDoesNotExist error when using any feature of Crispy Forms.

As I'm new to Crispy Forms (which seems to be universally recommended for quickly making forms look better), I have followed the instructions at https://django-crispy-forms.readthedocs.io/en/latest/install.html and as far as I know, the installation is correct (installed using pip and changes in settings.py). I am running this in a virtual environment (the .venv folder referred to below) on a Windows machine.

I have even created a new project specifically to look at this, with absolutely minimal content, and the same problem persists. The project is called 'stuff' and the single app in it 'other'.

settings.py

...

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'other',
'bootstrap4'
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'

...

results of pip freeze

beautifulsoup4==4.12.2
Django==4.1.9
django-bootstrap4==23.1
django-crispy-forms==2.0
django-mongodb-engine==0.6.0
djangotoolbox==1.8.0
djongo==1.3.6
dnspython==2.3.0
mongoengine==0.27.0
psycopg2==2.9.6
pymongo==4.3.3
pytz==2023.3
soupsieve==2.4.1
sqlparse==0.2.4
tzdata==2023.3
Enter fullscreen mode Exit fullscreen mode

Solution

pip uninstall bootstrap4
Enter fullscreen mode Exit fullscreen mode

settings.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.staticfiles',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',

'employee',
'employee_register',
'bootstrap4',
'crispy_forms',
'crispy_bootstrap4'

]

now crispy_forms is working

{% block content %}
<form action="" method="post" autocomplete="off">
    {% csrf_token %}
<p>{{form|crispy}}</p>
</form>
{% endblock content %}
Enter fullscreen mode Exit fullscreen mode

Reference

Top comments (0)