0

i have simple django/python app and i got 1 page - create.html. So i want to extend this page to use index.html. Everything work (no errors) and when the page is loaded all data from create.html and all text from index.html present but no formating is available - images and css that must be loaded from index.html is not loaded. When i load index.html in browser looks ok. Can someone help me?

Thanks!

here is the code of templates:

create.html

    {% extends "index.html" %}

{% block title %}Projects{% endblock %}

{% block content %}
    {% if projects %}
        <table  border="1">
            <tr>
                <td align="center">Name</td>
                <td align="center">Description</td>
                <td align="center">Priority</td>
                <td align="center">X</td>
            </tr>
            {% for p in projects %}
            <tr>
                <td> <a href="/tasks/{{p.id}}/">{{p.Name}}</a> </td>
                <td>{{p.Description}} </td>
                <td> {{p.Priority.Name}} </td>
                <td> <a href="/editproject/{{p.id}}/">Edit</a> <a href="/deleteproject/{{p.id}}/">Delete</a> </td>
            <tr>
            {% endfor %}
        </table>
    {% else %}
        <p>No active projects.</p>
    {% endif %}
{% endblock %}

and index.html:

    <html>
    <head>
        {% block title %}{% endblock %}

        <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    </head>
    <body>
    {% block content %}{% endblock %}

<div class="PostContent">

<img class="article" src="images/spectacles.gif" alt="an image" style="float: left" />
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<p>Lorem ipsum dolor sit amet,
<a href="#" title="link">link</a>, <a class="visited" href="#" title="visited link">visited link</a>, 
 <a class="hover" href="#" title="hovered link">hovered link</a> consectetuer 
adipiscing elit. Quisque sed felis. Aliquam sit amet felis. Mauris semper, 
velit semper laoreet dictum, quam diam dictum urna, nec placerat elit nisl 
in quam. Etiam augue pede, molestie eget, rhoncus at, convallis ut, eros.</p>

    ....
    </body>
    </html>  
4

3 回答 3

1

啊哈发现问题出在哪里!未设置 MEDIA_ROOT 和 MEDIA_URL :-( 编辑它们后一切正常。

Django 模板看不到 CSS 文件

于 2009-09-11T21:02:06.733 回答
1

更具体地说,查看 content.html 的第一行:

  {% extends "base.html" %}

将此更改为

  {% extends "index.html" %}

(或将 index.html 重命名为 base.html)

于 2009-09-11T18:50:36.273 回答
1

看起来您正在扩展 base.html 而不是 index.html。

于 2009-09-11T18:41:33.877 回答