Reputation: 1047
I saw this question on SO: Django crispy-forms cannot find CSS, and followed all of the suggestions in the accepted answer, i.e.:
Also: I am trying to use the bootstrap template pack, so I added CRISPY_TEMPLATE_PACK = 'bootstrap' into my settings.py file.
When I load the form created by the example from https://gist.github.com/maraujop/1838193, there is no CSS on the page. Any advice? Thanks!
Edit: I think I'm still missing something. I downloaded Bootstrap, unzipped it into a static dir inside my app, i.e.:
my_app/
static/
css/
js/
img/
I created a base.html:
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="{{ STATIC_URL }}css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
In my template, I have:
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block content %}
{% crispy form %}
{% endblock %}
When I try and load my page, the form loads (whew), but still no CSS. When I look at the source of the page, I can see the following:
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
but Django can't seem to find the file.
Upvotes: 5
Views: 7755
Reputation: 27
You need to do pip install crispy_bootstrap4
4 or 5 based on your requirements.
Add it to the INSTALLED_APPS
list and add these to the settings.py
file:
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
CRISPY_TEMPLATE_PACK = "bootstrap4"
Upvotes: -1
Reputation: 11269
You need to include the css/js yourself. So... Download bootstrap, put the files in your static files directory, include a link to the bootstrap css/js files in your base.html
template, then you will be able to see the proper formatting.
Upvotes: 7