1

manage.pyrunserverを使用してDJango1.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>

このURLhttp:// 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>

他の人もこれにぶつかっているようです私はこの Django1.3静的ファイルがアプリケーションディレクトリに配置されているのを見つけました

4

2 に答える 2

0

seetings.pyを確認してください。STATIC_URLの定義が間違っているようです。

ドキュメントを見てください:https ://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATIC_URL

于 2011-05-29T15:02:18.287 に答える
0

スタイルシートは初めてです。base.htmlに次のスタイルシートエントリを含めるのを忘れたので、うまくいきました。ファイル日付ピッカーはまだしませんが。

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