Error when using crispy forms with Django and bootstrap
Question:
I have created a sign in page for my blog, using bootstrap and django. I recently imported crispy forms and when I try and go to the page I get the following error: TemplateDoesNotExist at /register/
. However all my redirects and URLs are setup correctly.
On the Django debug it says that the error is in my base HTML file, under the head section where I imported bootstrap CSS. I can provide any code necessary. It says this on my server: django.template.exceptions.TemplateDoesNotExist: bootsrap4.4.1/uni_form.html
.
Answers:
set CRISPY_TEMPLATE_PACK = 'bootstrap4'
. Looks like you have it currently set to the full version number.
I encountered similar issue and then realized that it depends on what Bootstrap version you’ve either installed or which version CDN you’re referring to in your template. I used ‘bootstrap4’ as the CRISPY-TEMPLATE_PACK in my settings.py, but in my base.html template, i’m using Bootstrap5 CDN, therefore Django is not able to retrieve bootstrap4/uni_form.html.
So make sure your template is using the same version of Bootstrap as the one you put in your settings.py.
install this version of django-crispy-forms "django-crispy-forms==1.14.0" and your problems will be solved.
Regarding django-crispy-forms templates packs are now in separate package,
depending on the boostrap version you are using, You will need to pip install crispy-bootstrap4
and add crispy_bootstrap4
to your list of INSTALLED_APPS.
That will solve your issue
I have created a sign in page for my blog, using bootstrap and django. I recently imported crispy forms and when I try and go to the page I get the following error: TemplateDoesNotExist at /register/
. However all my redirects and URLs are setup correctly.
On the Django debug it says that the error is in my base HTML file, under the head section where I imported bootstrap CSS. I can provide any code necessary. It says this on my server: django.template.exceptions.TemplateDoesNotExist: bootsrap4.4.1/uni_form.html
.
set CRISPY_TEMPLATE_PACK = 'bootstrap4'
. Looks like you have it currently set to the full version number.
I encountered similar issue and then realized that it depends on what Bootstrap version you’ve either installed or which version CDN you’re referring to in your template. I used ‘bootstrap4’ as the CRISPY-TEMPLATE_PACK in my settings.py, but in my base.html template, i’m using Bootstrap5 CDN, therefore Django is not able to retrieve bootstrap4/uni_form.html.
So make sure your template is using the same version of Bootstrap as the one you put in your settings.py.
install this version of django-crispy-forms "django-crispy-forms==1.14.0" and your problems will be solved.
Regarding django-crispy-forms templates packs are now in separate package,
depending on the boostrap version you are using, You will need to pip install crispy-bootstrap4
and add crispy_bootstrap4
to your list of INSTALLED_APPS.
That will solve your issue