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

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

问题描述

Django版本是1.4。我已经阅读了官方文件,并且google了我的问题。



首先我遵循了官方文件管理静态文件将其添加到 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 ...> 

但在我的博客中是:

 < link href =css / main.css...> (只需将STATIC_URL显示为空)

我的设置是:

  STATIC_ROOT = os.path.join(PROJECT_PATH,'static')
STATIC_URL ='/ static /'
视图中,c>

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


解决方案

更改

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

to

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


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

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',
)

In my template:

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

but, in my broswer is:

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

My settings is:

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

in my views

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

解决方案

Change

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

to

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

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

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