Reputation: 71
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
Upvotes: 5
Views: 10517
Reputation: 176
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>
Upvotes: 1
Reputation: 2350
first you should tell the django that app you made actualy exist. go to setting.py and go to Installed_app and include your app there like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'preview.apps.PreviewConfig',
]
then you must go to main directory and run urls.py and add this url:
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^$', include ('preview.urls')),
url(r'^admin/', admin.site.urls),
]
after this you sould make a python file in preview folder and call it urls.py.and there you must define your url patten for your preview app.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', IndexView.as_view()),
]
the final step is you must define views .in order to do that go to views.py in previews folder and run views.py
from django.views.generic import TemplateView
class IndexView(TemplateView):
template_name = "index.html"
Upvotes: 0
Reputation: 71
Answer to is question is human error. I had a type in the code, most likely a spacing issue (sadly I am not using eclipse). The answer to this read hard and double check everything before posting, or you will have to be very contrite (like me!). I'm off to hide under the django rock I crawled out from under! Happy coding!
Upvotes: 0
Reputation: 36
Try insert {% block content %} in your catalog.html or base.html your problem would be because you are inheriting from catalog < base and on those templates don't have this block for render.
Upvotes: 0