python - django 1.11 中找不到静态文件

标签 python django path django-staticfiles static-files

我得到"Not Found"访问本地主机上的任何页面时。 我已阅读所有相关帖子,但仍然无法理解原因。

我已将 'django.contrib.staticfiles' 包含在 INSTALLED_APPS 中。

我的settings.py中有DEBUG = TRUE

我的项目布局和代码如下。

提前谢谢您。

repo_root
├── manage.py
│   
├── project_root
│   │
│   ├── accounts
│   │   ├── migrations
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── views.py
│   │   └── urls.py
│   │
│   ├── templates
│   │   └── index.html   
│   │
│   └── static
│       └── assets
│           ├── bootstrap
│           ├── css
│           ├── fonts
│           ├── img
│           └── js
│   
├── config_root
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
│  

设置.py

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(
        BASE_DIR,
        'project_root/static/assets')
]

STATIC_ROOT = os.path.join(
    BASE_DIR,
    'project_root/staticfiles')

index.html

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>index</title>
    <meta name="description" content="sample_content">
    <link rel="stylesheet" href="'static/assets/bootstrap/css/bootstrap.min.css'">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,400i,700,700i,600,600i">
    <link rel="stylesheet" href="'static/assets/fonts/simple-line-icons.min.css'">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.10.0/baguetteBox.min.css">
    <link rel="stylesheet" href="'static/assets/css/smoothproducts.css'">
</head>

url.py

url(r'^index/$', IndexView.as_view())

View .py

class IndexView(TemplateView):
    template_name = "index.html"

最佳答案

我没有,

{%加载静态%}

href="{% static 'assets/bootstrap/css/bootstrap.min.css' %}"

添加这些解决了问题。

谢谢!

关于python - django 1.11 中找不到静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53458321/

相关文章:

c - 在 C++ 程序中指定路径

python - 仅获取 pyswarm 粒子生成的整数

django - 在 Django 中访问移动浏览器位置数据

c# - 需要绝对路径?

java - 在 Jar 中定位资源

linux - 使用heroku调度程序调度websolr重新索引

python - 在给定范围内查找列表的所有可能子列表的高效和 Pythonic 方法,以及将其中的所有元素相乘后的最小乘积?

python - 是否可以在 Octave 中使用 Python 模块?

python - 在 Python 中乘以字符串时使用 sep

python - 让 Django 仅返回存储为 models.TextField() 的文本的前 50 个字符