Django STATIC_URL 不工作 [英] Django STATIC_URL is not working

查看:26
本文介绍了Django STATIC_URL 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django 版本是 1.4.我已经阅读了官方文档,并用谷歌搜索了我的问题.

Django version is 1.4. I had read the official document, and googled my problem.

首先我遵循了官方文档管理静态文件settings.py 中添加:

first I had followed the official document Managing static files added this in settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (
  'django.core.context_processors.debug',
  'django.core.context_processors.i18n',
  'django.core.context_processors.media',
  'django.core.context_processors.static',
  'django.contrib.auth.context_processors.auth',
  'django.contrib.messages.context_processors.messages',
)

在我的模板中:

<link href="{{ STATIC_URL }}css/main.css" ...>

但是,在我的浏览器中是:

but, in my broswer is:

<link href="css/main.css" ...> (Just render `STATIC_URL` as empty)

我的设置是:

STATIC_ROOT = os.path.join(PROJECT_PATH, 'static')
STATIC_URL = '/static/'

在我的视图

def register(request):
    ...
    return render_to_response('register.html', {'errors':errors})

推荐答案

更改

return render_to_response('register.html', 'errors':errors)

return render_to_response('register.html', {'errors': errors}, RequestContext(request))

这篇关于Django STATIC_URL 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆