Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django renders a blank page

Firstly, I'd like to admit, I'm a completely new to Django. I'm learning as best as I can. I am working my way through a book called "Beginning Django E-Commerce". Without wishing to breach the copy right, perhaps you guys can spot where I have gone wrong. I am using Django 1.4.3, the book I'm using was probably written for Django 1, maybe 1.1, but here goes.

my base.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "XHTML1-s.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{% block title %}{% if page_title %}{{ page_title }} - {% endif %}
            {{ site_name }}{% endblock %}</title>
    <meta name="keywords" content="{{ meta_keywords }}" />
    <meta name="description" content="{{ meta_description }}" />
</head>
<body>
    {% block site_wrapper %}{% endblock %}
</body>
</html>

my catalog.html:

{% extends "base.html" %}

{% block site_wrapper %}
<div id="main">
    <a href="#content" class="skip_link">Skip to main content</a>
    <div id="banner">
            <div class="bannerIEPadder">
                    <div class="cart_box">
                            [link to cart here]
                    </div>
                    Modern Musician
            </div>
    </div>
    <div id="navigation">
            <div class="navIEPadder">
                    [navigation here]
            </div>
    </div>
    <div id="middle">
            <div id="sidebar">
                    <div class="sidebarIEPadder">
                            [search box here]
                    <br />
                            [category listing here]
                    </div>
            </div>
            <div id="content">
                    <a name=”content”></a>
                    <div class="contentIEPadder">
                            {% block content %}{% endblock %}
                    </div>
            </div>
    </div>
    <div id="footer">
            <div class="footerIEPadder">
                    [footer here]
            </div>
    </div>
</div>
{% endblock %}

My index.html:

{% extends "catalog.html" %}

{% block content %}
    <h2>Welcome!</h2>
{% endblock %}

All of these files are stored in a templates directory. The book at this point suggests I run the following command:

python manage.py startapp preview

and adjust my urls.py:

urlpatterns = patterns('', … (r'^catalog/$', 'preview.views.home'), )

adjust the views.py under the preview directory:

from django.shortcuts import render_to_response

def home(request):
  return render_to_response("index.html")

Then you should be able to see a page that says:

Skip to main content [link to cart here] Modern Musician [navigation here] [search box here] [category listing here] Welcome! [footer here]

However, all I get is a blank page. Can anyone work out why? (it is possible the book is simply out of date) When I view the source of the blank page.

which is effectively a blank rendering of the base.html. In the development server, I have no errors:

python manage.py runserver localhost:8000      (wd: ~/websites/ecomstore) 
Validating models... 0 errors found Django version 1.4.3, using settings 'ecomstore.settings' 
Development server is running at http://www.localhost.com:8000/ Quit the server with CONTROL-C. 
[01/Apr/2013 02:13:06] "GET /catalog/ HTTP/1.1" 200 352 
[01/Apr/2013 02:13:08] "GET /catalog/ HTTP/1.1" 200 352 
[01/Apr/2013 02:13:09] "GET /catalog/ HTTP/1.1" 200 352 
[01/Apr/2013 02:33:33] "GET /catalog/ HTTP/1.1" 200 352

full list of my steps, please see this site

like image 632
LeeO Avatar asked Nov 25 '22 02:11

LeeO


1 Answers

You must add {% block content %} on base.html

For example this code base.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "XHTML1-s.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{% block title %} {% if page_title %} {{ page_title }} - {% endif %}
            {{ site_name }} {% endblock %} </title>
    <meta name="keywords" content="{{ meta_keywords }}" />
    <meta name="description" content="{{ meta_description }}" />
</head>
<body>
    {% block site_wrapper %}{% endblock %}
    {% block content %}{% endblock %} <!-- you can move this line to first block -->
</body>
</html>
like image 103
Amarulloh M Khoeri Avatar answered Nov 26 '22 16:11

Amarulloh M Khoeri