加载静态在 Django 中不起作用
Load staticfies do not work in Django
我是 python 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/'
但是在浏览器中,样式表没有加载成功。
EDIT-1
css 结构:
您已将静态文件放入模板文件夹中。那不是他们要去的地方。您需要将它们放在您的应用程序中或 STATICFILES_DIRS 设置引用的文件夹中。
我是 python 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/'
但是在浏览器中,样式表没有加载成功。
EDIT-1
css 结构:
您已将静态文件放入模板文件夹中。那不是他们要去的地方。您需要将它们放在您的应用程序中或 STATICFILES_DIRS 设置引用的文件夹中。