DJando CSS

一、问题

resource interpreted as stylesheet but transferred with mime type text/html

 

原因:css文件加载不成功

 

二、解决方法

将css的文件放在static目录下,static和templates在同一个目录。结构图如下所示:

iot_app
├── admin.py
├── admin.pyc
├── __init__.py
├── __init__.pyc
├── migrations
│   ├── 0001_initial.py
│   ├── 0001_initial.pyc
│   ├── 0002_auto_20150317_1623.py
│   ├── 0002_auto_20150317_1623.pyc
│   ├── __init__.py
│   └── __init__.pyc
├── models.py
├── models.pyc
├── static
│   ├── css
│   │   ├── bootstrap.css
│   │   ├── bootstrap.css.map
│   │   ├── bootstrap.min.css
│   │   ├── bootstrap-theme.css
│   │   ├── bootstrap-theme.css.map
│   │   └── bootstrap-theme.min.css
│   ├── fonts
│   │   ├── glyphicons-halflings-regular.eot
│   │   ├── glyphicons-halflings-regular.svg
│   │   ├── glyphicons-halflings-regular.ttf
│   │   ├── glyphicons-halflings-regular.woff
│   │   └── glyphicons-halflings-regular.woff2
│   ├── images
│   │   ├── chrome.png
│   │   ├── firefox.png
│   │   ├── ie.png
│   │   ├── opera.png
│   │   └── safari.png
│   └── js
│   ├── bootstrap.js
│   ├── bootstrap.min.js
│   ├── html5shiv.js
│   ├── html5shiv.min.js
│   ├── jquery-1.11.1.js
│   ├── jquery-1.11.1.min.js
│   ├── jquery-1.11.1.min.map
│   ├── jquery-1.11.2.min.js
│   ├── jquery-1.11.2.min.map
│   ├── npm.js
│   └── respond.min.js
├── templates
│   ├── base.html
│   ├── buttons.html
│   ├── contact.html
│   ├── form.html
│   ├── form_inline.html
│   ├── formset.html
│   ├── form_using_template.html
│   ├── index.html
│   ├── login.html
│   ├── pagination.html
│   └── tabs.html
├── tests.py
├── views.py
└── views.pyc
设置setting.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)


在html文件中,加载css或者js的地方写成如下形式:

{% load staticfiles %}
<link rel="stylesheet" href="{% static 'assets/css/amazeui.min.css' %}">
<link rel="stylesheet" href="{% static 'assets/css/admin.css' %}">
<script src="{% static 'assets/js/jquery.min.js' %}"></script>
<script src="{% static 'assets/js/amazeui.min.js' %}"></script>
<script src="{% static 'assets/js/app.js' %}"></script>


记得在开头加载一下static文件:

{% load staticfiles %}


另外要注意的是:

(1)setting.py中的INSTALLED_APPS中包含django.contrib.staticfiles

(2)setting.py中DEBUG选项为True,否则无法映射到静态文件目录
---------------------
作者:小拳头
来源:CSDN
原文:https://blog.csdn.net/xiaoquantouer/article/details/52063397
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-03-20 09:45  飞天FOX  阅读(137)  评论(0编辑  收藏  举报