简体   繁体   English

静态文件未随Django一起加载。 (引导程序不起作用)

[英]Static files not loading with Django. (Bootstrap not working)

I have read many posts about the topic and tried to follow all the suggestions (new to python here) but I am unable to get bootstrap to work in Django. 我已经阅读了很多有关该主题的文章,并尝试遵循所有建议(这里是python的新手),但是我无法在Django中使用引导程序。

I have a project "myoffice" and an app "proposals" in it. 我有一个项目“ myoffice”和一个应用程序“ proposals”。

I have downloaded a css file and put it in following folder 我已经下载了一个css文件并将其放在以下文件夹中

django\\bin\\myoffice\\proposals\\static\\bootstrap\\bootstrap.min.css Django的\\ BIN \\ myoffice \\建议\\静\\引导\\ bootstrap.min.css

I have made following changes to the settings.py 我对settings.py进行了以下更改

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATICFILES_DIRS = (

os.path.join(
        os.path.dirname(__file__),
        'static',
)

STATIC_URL = 'proposals/static/'

and included static files in my template like this. 并在这样的模板中包含静态文件。

<!DOCTYPE html>

<html>
<head>
    {% load staticfiles %}
    <link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet" media="screen">
</head>
<body>

But it is still showing view without any formatting. 但是它仍然显示没有任何格式的视图。

I figured it out. 我想到了。 It was actually a stupid error. 这实际上是一个愚蠢的错误。 I discovered, I have to restart the webserver after adding css file to the static directory and making changes to the settings.py 我发现,在将css文件添加到静态目录并更改settings.py之后,必须重新启动Web服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM