当我在浏览器中使用url(r'^consultar/$', 'rcb.core.views.consultar'),时,consultar.html文件查找jquery-1.11.2.min.js文件,显示以下信息:
Remote Address:127.0.0.1:8000
Request URL:http://localhost:8000/static/js/jquery-1.11.2.min.js
Request Method:GET
Status Code:200 OK但是当我在浏览器http://localhost:8000/proposta/consultar/中使用http://localhost:8000/proposta/consultar/时,consultar.html文件找不到jquery-1.11.2.min file.js。出现以下错误:
Remote Address:127.0.0.1:8000
Request URL:http://localhost:8000/proposta/static/js/jquery-1.11.2.min.js
Request Method:GET
Status Code:404 NOT FOUND有人能帮我修复运行url http://localhost:8000/proposta/consultar/的代码吗?
以下是文件和目录的代码和结构:
consultar.html
{% extends 'base.html' %}
....base.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../static/js/jquery-1.11.2.min.js" type="text/javascript"></script>
</head>
<body>
{% block corpo %}{% endblock %}
</body>
</html>views.py
def consultar(request):
propostas_salvas=search()
return render_to_response('consultar.html', { 'propostas_salvas' : propostas_salvas}, context_instance=RequestContext(request))我的文件和目录结构是:
rcb (Project)
core (is the App)
static
js
jquery-1.11.2.min.js
template
base.html
consultar.html
views.py
...
...
... 发布于 2015-03-01 12:47:39
您应该使用相对于您的域的javascript路径,而不是您所请求的文档,因为对于每个文档,javascript的相对路径将是不同的。所以,改变这句话:
<script src="../static/js/jquery-1.11.2.min.js" type="text/javascript"></script>转入:
<script src="/static/js/jquery-1.11.2.min.js" type="text/javascript"></script>或者更好的是,在模板中加载静态文件并使用django中内置的静态文件管理:
<script src="{% static "js/jquery-1.11.2.min.js" %}" type="text/javascript"></script>这样,您以后可以在设置中更改您的STATIC_URL,django将纠正您的静态文件的路径。即使它们位于不同的域(一些CDN或非cookie域仅用于静态文件)。
https://stackoverflow.com/questions/28793582
复制相似问题