开发者

DJango Static Content for JQuery css not rendering H1, H2 properly in template

开发者 https://www.devze.com 2023-03-09 05:55 出处:网络
Doing DJango 1.3 local development using manage.py runserver Created a directory called static in my application directory

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/$', direct_to_template, {
            'template': 'widget.html'
    }),
) 

My widget.html template

{% extends "base.html" %}
{% block title %}Test Widget{% endblock %}
{% block content %}
Here is the Date picker
<form action开发者_StackOverflow社区="" 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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消