尝试在我的Django模板中使用Orbit Foundation滑块时遇到问题。
从头开始生病:
我的Django项目url.py文件只有一个网址:
url(r'^', include('myapp.urls')),
应用程序的url.py文件包含:
url(r'^', 'myapp.views.content'),
然后是views.py文件:
def content(request):
person_name = Persons.objects.all()[:10].values('name')
person_id = Persons.objects.all()[:10].values('id')
return render_to_response('index.html', {'persons_names': person_name, 'persons_ids': person_id})
我的index.html包含一些基本信息,并扩展了base.html:
{% extends 'base.html' %}
{% block content %} some divs {% endblock %}
我认为Base.html文件非常标准:
{% load staticfiles %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title> {% block title %} MyTitle {% endblock %} </title>
<link rel="stylesheet" type="text/css" href="{% static "static/css/foundation.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "static/foundation-icons/foundation-icons.css" %}">
<script type="text/javascript" src="{% static "static/js/foundation/foundation.js" %}"></script>
<script type="text/javascript" src="{% static "static/js/foundation/foundation.orbit.js" %}"></script>
<script type="text/javascript" src="{% static "static/js/vendor/jquery.js" %}"></script>
</head>
<body>
<div class="header">
{% block header %}
{% include 'header.html' %}
{% endblock %}
</div>
{% block content %} {% endblock %}
<footer>
{% block footer %}
{% include 'footer.html' %}
{% endblock %}
</footer>
</body>
</html>
实际上问题始于我要插入轨道滑块的header.html模板:
{% block header %}
<ul class="example-orbit-content" data-orbit>
<li data-orbit-slide="headline-1">
<div>
<h2>Headline 1</h2>
<h3>Subheadline</h3>
</div>
</li>
<li data-orbit-slide="headline-2">
<div>
<h2>Headline 2</h2>
<h3>Subheadline</h3>
</div>
</li>
</ul>
{% endblock %}
轨道对我不起作用。所有这些h1和h2标签都是一个接一个地显示,而不是必须格式化。我的意思是,我只是从基础文档页面复制粘贴测试轨道代码......我认为它应该正常工作 - )
顺便说一句,settings.py包含所有必需的数据(我猜):
STATIC_URL = '/static/'
STATICFILES_DIRS = (
('static', '/home/me/Documents/Django_apps/my_project/static/'),
)
INSTALLED_APPS = (
.....
'django.contrib.staticfiles'
.....
)
似乎django没有看到我的js文件......我做错了什么? 感谢。
更新: 关于我的CSS和JS文件的控制台“GET”消息如下:
"GET /static/static/js/vendor/jquery.js HTTP/1.1" 304 0
答案 0 :(得分:0)
您的问题出在 base.html 文件中。您不应该使用static/
为所有静态资产添加前缀。看起来应该更像这样:
<强> base.html文件强>
<head>
<title> {% block title %} MyTitle {% endblock %} </title>
<link rel="stylesheet" type="text/css" href="{% static "css/foundation.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "foundation-icons/foundation-icons.css" %}">
<script type="text/javascript" src="{% static "js/foundation/foundation.js" %}"></script>
<script type="text/javascript" src="{% static "js/foundation/foundation.orbit.js" %}"></script>
<script type="text/javascript" src="{% static "js/vendor/jquery.js" %}"></script>
</head>