1

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

设置.py

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

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

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

4

2 回答 2

0

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

<style type="text/css">
            body{ font: 62.5% "Trebuchet MS", sans-serif; margin: 50px;}
        </style>
于 2011-05-30T02:29:27.117 回答
0

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

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

于 2011-05-29T15:02:18.287 回答