bootstrap和djang的集成问题

2024-09-28 03:14:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过将引导文件夹从引导文件夹复制粘贴到静态文件夹来集成引导和Django。但我无法进入引导.css文件。显示404错误。我什么都照文件上说的做了,但运气不好。我正在使用django 2.x,但我也尝试了/static和<;%static%>;。你知道吗

.
├── blackowl
│   ├── blackowl
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── __init__.py
│   │   ├── migrations
│   │   │   └── __init__.py
│   │   ├── models.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-36.pyc
│   │   │   └── views.cpython-36.pyc
│   │   ├── tests.py
│   │   └── views.py
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── settings.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   └── wsgi.cpython-36.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── db.sqlite3
├── index.html
├── manage.py
├── static
│   ├── bootstrap
│   │   ├── css
│   │   │   └── bootstrap.min.css
│   │   └── js
│   │       └── bootstrap.min.js
│   ├── css
│   │   ├── Login-Form-Dark.css
│   │   └── styles.css
│   ├── fonts
│   │   ├── ionicons.eot
│   │   ├── ionicons.min.css
│   │   ├── ionicons.svg
│   │   ├── ionicons.ttf
│   │   └── ionicons.woff
│   ├── img
│   │   └── star-sky.jpg
│   └── js
│       └── jquery.min.js
└── templates
    └── index.html

在设置.py你知道吗

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_URL = '/static/'

在索引.html你知道吗

     <!DOCTYPE html>
    {% load static %}
header
     <link rel="stylesheet" href="{% static '/fonts/ionicons.min.css' %}">

图像

background: #475d62 url("{% static 'img/star-sky.jpg' %}");

Tags: 文件pathpy文件夹initoshtmljs
1条回答
网友
1楼 · 发布于 2024-09-28 03:14:52

在开发模式下,静态文件必须位于应用程序级目录中。 Django将在开发模式下提供静态文件时查看相应的应用程序目录

在您的情况下,将静态目录移动到blackowl/blackowl。你知道吗

<link rel="stylesheet" href="{% static 'fonts/ionicons.min.css' %}">

要从位于css/styles.css的css提供静态文件:

使用静态文件的相对路径。你知道吗

 background: #000 url(../img/star.png);

Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg.

此处包含的文档managing static files

相关问题 更多 >

    热门问题