JQuery css 的 DJango 静态内容未在模板中正确渲染 H1、H2

发布于 2024-11-11 06:50:39 字数 3294 浏览 3 评论 0原文

使用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 的 JQuery 样式, H2、H3 不渲染。日历选择器也不是。

<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 静态文件放置在应用程序目录中

Doing DJango 1.3 local development using manage.py runserver

Created a directory called static in my application directory

C:/Documents and Settings/Administrator/workspace/mysite/src/mysite/static/

Put JQuery files in

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/

My widget.html template

{% 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 %}

My base.html template

<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>

Going to this URL http://localhost:8000/widget/ renders below, but the JQuery styles for H1, H2, H3 aren't rendered. Neither is the calendar picker.

<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>

Seems others are hitting this too I found this Django 1.3 static files placed in application dirs

, direct_to_template, { 'template': 'widget.html' }), )

My widget.html template

My base.html template

Going to this URL http://localhost:8000/widget/ renders below, but the JQuery styles for H1, H2, H3 aren't rendered. Neither is the calendar picker.

Seems others are hitting this too I found this Django 1.3 static files placed in application dirs

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不寐倦长更 2024-11-18 06:50:39

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

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

Check your seetings.py, STATIC_URL seems to be defined wrong.

Look at the documentation: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATIC_URL

北城半夏 2024-11-18 06:50:39

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

<style type="text/css">
            body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
        </style>

New to style sheets. I forgot to include following style sheet entries in base.html then it worked. Although the file date picker still doesn't.

<style type="text/css">
            body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
        </style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文