2017-07-13 17 views
0

我是新的python Django。加載staticfies不工作在Django

我有這樣低於項目:

但在我TestModel APP,這裏有一個index.html的:

<!doctype html> 
{% load staticfiles %} 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta name="Keywords" content="" /> 
    <meta name="description" content="" /> 
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" /> --> 
    <title>Python探索館 - Slice</title> 
    <!-- Main Theme --> 
    <link rel="stylesheet" href="{% static 'css/style.css' %}" /> 

    <!-- Font --> 
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_n5vylbuqe61or.css" /> 
    </head> 
<body> 
... 

你看,我有加載靜態文件。

而在我testdj/settings.py,我已經設置了STATIC_URL

STATIC_URL = '/static/' 

但在瀏覽器中,樣式表沒有加載成功。

enter image description here


EDIT-1

的CSS structrue:

enter image description here

+0

嘗試'{%load static%}'並提供您的settings.py文件,否則我無法確定錯誤來自哪裏,因爲通常情況下您會將'static'文件夾放在應用程序文件夾中,而不是裏面的模板文件夾 –

+0

@ N.Ivanov我試過了,不行。 – 244boy

+1

用你的'settings.py'文件更新你的答案 –

回答

3

你已經把你靜態文件在您的模板文件夾中。那不是他們去的地方。您需要將它們放入您的應用程序或STATICFILES_DIRS設置所引用的文件夾中。

+0

我這樣做,因爲教程說如果我在這裏有多個APP,有一個TestModel目錄我們可以區分它們。 – 244boy