【发布时间】:2012-11-06 22:24:25
【问题描述】:
我还是 django 的新手,我的 CSS 工作有问题。
我遵循了链接中的指示:Django Static Link tutorial,关于处理静态文件。但它仍然无法正常工作。
设置
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/Users/a9austin/Development/sites/AlphaSocks/src/static_root/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/Users/a9austin/Development/sites/AlphaSocks/src/staticfiles'
)
查看
#from django.http import HttpResponse
from django.shortcuts import render_to_response
def index(request):
return render_to_response('index.html')
index.html
<link rel="stylesheet" href="{{STATIC_URL}}css/style.css" type="text/css" media="screen" >
和目录组织
src->staticfiles->css->style.css
非常感谢您,非常感谢您的帮助和时间!
【问题讨论】:
-
“什么”不起作用?如何使用 render() 或 render_to_response() 渲染视图? settings.py 中是否开启了静态文件上下文处理器?
-
是的,我正在使用 render_to_response,我会用我的视图更新它。它不起作用的 css 实际上并没有改变我的 html。
-
看这个post来处理静态文件
-
@OtskimanotSqilal 感谢您的回复,我刚刚用我的 STATICFILES_DIR 更新了它,我的 css 仍然没有出现。
-
你配置
STATICFILES_DIRS和STATIC_ROOT的方式不对。它们不能包含相同的目录。请参阅我的答案以获取更多信息。
标签: python html css django web