Django脆皮形式不加载CSS [英] Django crispy forms not loading CSS
问题描述
我在此看到这个问题: Django crispy-forms无法找到CSS ,并遵循所接受的答案中的所有建议,即:
I saw this question on SO: Django crispy-forms cannot find CSS, and followed all of the suggestions in the accepted answer, i.e.:
- 'crispy-forms'列在INSTALLED_APPS
- 我没有运行生产服务器,所以我不知道应用了收集的选项(虽然我已经运行了)
另外:我试图使用引导模板包,所以我将CRISPY_TEMPLATE_PACK ='bootstrap'添加到我的settings.py文件中。
Also: I am trying to use the bootstrap template pack, so I added CRISPY_TEMPLATE_PACK = 'bootstrap' into my settings.py file.
当我加载由 https://gist.github.com/maraujop/1838193,页面上没有CSS。任何建议?谢谢!
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!
编辑:
我想我还是缺少一些东西。我下载了Bootstrap,将其解压缩到我应用程序的静态目录中,即:
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/
我创建了一个基础。 html:
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>
在我的模板中,我有:
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block content %}
{% crispy form %}
{% endblock %}
当我尝试加载我的页面时,表单加载(呃),但还没有CSS。当我查看页面的来源时,我可以看到以下内容:
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">
但Django似乎找不到该文件。
but Django can't seem to find the file.
推荐答案
您需要自己包括css / js 。所以... 下载引导,将文件放在静态文件目录中,包括一个链接到引导您的 base.html
模板中的css / js文件,那么您将可以看到正确的格式。
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.
这篇关于Django脆皮形式不加载CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!