如何解决jQuery的DJango静态内容无法在模板中正确呈现H1,H2
| 使用manage.py runserver进行DJango 1.3本地开发 在我的应用程序目录中创建了一个名为static的目录C:/Documents and Settings/Administrator/workspace/mysite/src/mysite/static/
将JQuery文件放入
C:\\Documents and Settings\\Administrator\\workspace\\mysite\\src\\mysite\\static\\css\\custom-theme\\jquery-ui-1.8.13.custom.css
C:\\Documents and Settings\\Administrator\\workspace\\mysite\\src\\mysite\\static\\js\\jquery-1.5.1.min.js
C:\\Documents and Settings\\Administrator\\workspace\\mysite\\src\\mysite\\static\\js\\jquery-ui-1.8.13.custom.min.js
Settings.py
STATICFILES_FINDERS = (
\'django.contrib.staticfiles.finders.FileSystemFinder\',\'django.contrib.staticfiles.finders.AppDirectoriesFinder\',)
STATIC_ROOT = \'\'
STATIC_URL = \'http:/localhost:8000/\'
urls.py
urlpatterns = patterns(\'\',(r\'^widget/$\',direct_to_template,{
\'template\': \'widget.html\'
}),)
我的widget.html模板
{% extends \"base.html\" %}
{% block title %}Test Widget{% endblock %}
{% block content %}
Here is the Date picker
<form action=\"\" method=\"post\">
<input type=\"text\" name=\"date\" id=\"date\" />
<input type=\"submit\" value=\"Submit\">
</form>
{% endblock %}
我的base.html模板
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link type=\"text/css\" href=\"{{ STATIC_URL }}css/custom-theme/jquery-ui-1.8.13.custom.css\" rel=\"Stylesheet\" />
<script type=\"text/javascript\" src=\"{{ STATIC_URL }}js/jquery-1.5.1.min.js\"></script>
<script type=\"text/javascript\" src=\"{{ STATIC_URL }}js/jquery-ui-1.8.13.custom.min.js\"></script>
</head>
<body>
{% load i18n %}
<h1>Top of mysite in base.html</h1>
{% block nav %} {% endblock %}
{% block content %}{% endblock %}
{% block footer %}
<H1> Footer top </H1>
<H2> Footer medium </H2>
<H3> Footer small </H3>
{% endblock %}
</body>
转到以下URL http:// localhost:8000 / widget /,但未呈现H1,H2,H3的JQuery样式。日历选择器也不是。
<html>
<head>
<title>Test Widget</title>
<link type=\"text/css\" href=\"http:/localhost:8000/css/custom-theme/jquery-ui-1.8.13.custom.css\" rel=\"Stylesheet\" />
<script type=\"text/javascript\" src=\"http:/localhost:8000/js/jquery-1.5.1.min.js\"></script>
<script type=\"text/javascript\" src=\"http:/localhost:8000/js/jquery-ui-1.8.13.custom.min.js\"></script>
</head>
<body>
<h1>Top of mysite in base.html</h1>
Here is the Date picker
<form action=\"\" method=\"post\">
<input type=\"text\" name=\"date\" id=\"date\" />
<input type=\"submit\" value=\"Submit\">
</form>
<H1> Footer top </H1>
<H2> Footer medium </H2>
<H3> Footer small </H3>
</body>
</html>
似乎其他人也遇到了这个问题我发现放在应用程序目录中的这个Django 1.3静态文件
解决方法
检查您的seetings.py,似乎STATIC_URL定义错误。
查看文档:https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATIC_URL
, 样式表的新功能。我忘了在base.html中包含以下样式表条目,然后它起作用了。尽管文件日期选择器仍然没有。
<style type=\"text/css\">
body{ font: 62.5% \"Trebuchet MS\",sans-serif; margin: 50px;}
</style>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。