首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JQuery css的DJango静态内容无法在模板中正确呈现H1和H2

JQuery css的DJango静态内容无法在模板中正确呈现H1和H2
EN

Stack Overflow用户
提问于 2011-05-29 22:46:10
回答 2查看 663关注 0票数 1

使用manage.py运行服务器进行DJango 1.3本地开发

在我的应用程序目录中创建了一个名为static的目录

代码语言:javascript
复制
C:/Documents and Settings/Administrator/workspace/mysite/src/mysite/static/

将JQuery文件放入

代码语言:javascript
复制
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

代码语言:javascript
复制
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

STATIC_ROOT = ''
STATIC_URL = 'http:/localhost:8000/'

urls.py

代码语言:javascript
复制
urlpatterns = patterns('',
    (r'^widget/$', direct_to_template, {
            'template': 'widget.html'
    }),
) 

我的widget.html模板

代码语言:javascript
复制
{% 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模板

代码语言:javascript
复制
<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样式。日历选取器也不是。

代码语言:javascript
复制
<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 static files placed in application dirs

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-30 10:29:27

样式表新手。我忘记在base.html中包含以下样式表项,然后它就起作用了。尽管文件日期选择器仍然不支持。

代码语言:javascript
复制
<style type="text/css">
            body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
        </style>
票数 0
EN

Stack Overflow用户

发布于 2011-05-29 23:02:18

检查您的seetings.py,STATIC_URL似乎定义错误。

查看文档:https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATIC_URL

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6168371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档