Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django crispy-forms cannot find CSS

I am using Django and Crispy Forms. I can get the form to render correctly, but no CSS formatting appears. What do I need to do?

I have added

CRISPY_TEMPLATE_PACK = 'bootstrap'

to my settings.py file.

The html file is as simple as it gets:

{% extends 'base.html' %}
{% load crispy_forms_tags %}

{% block content %}
   {% crispy form %}
{% endblock %}

What else is necessary to make it work? I understand that since the bootstrap files come bundled with crispy_forms, I don't need to copy and reference them specifically in my project's CSS path. Is this correct?

like image 459
Yaelgro Avatar asked Oct 21 '22 18:10

Yaelgro


2 Answers

It sounds as if your django instance can't find the static files for crispy forms. If you are running the development server, have you included 'crispy_forms' in INSTALLED_APPS?

If you're running a production server you'll probably need to ensure that your STATIC_FILES paths are correct and you've run collectstatic recently.

The authors have documented the installation process here - have you followed that completely?

like image 79
danodonovan Avatar answered Oct 30 '22 17:10

danodonovan


Its supposed to be {{ form|crispy }}, not {{ crispy form }}. You are putting the form through a filter (which is what | does in Django templates). Also, you forgot the {% csrf_token %}.

like image 26
Kovy Jacob Avatar answered Oct 30 '22 18:10

Kovy Jacob