-
Notifications
You must be signed in to change notification settings - Fork 7
Book Errata
Book errata I ran into while building the application. Note that since I bought this as a Kindle book I can't give pages numbers, so I'll refer to chapter and heading text, and I'll also include the Kindle location number.
In the section outlining the MIDDELWARE_CLASSES configuration for djangodblog it's missing an intermediate path, so in settings.py
instead of:
djangoblog.DBLogMiddleware
It needs to be:
djangodblog.middleware.DBLogMiddleware
Note that this error could be due to the fact that the book is potentially using an older version of djangodblog. I installed djangodblog using pip (sudo pip install django-db-log --upgrade
), which I'm assuming is the same as the latest from the GitHub repository Also note this project has been superseded by another project called Sentry but I wanted to stick with what the book uses.
Minor typo here that makes the application error out. Change this:
urlpatterns += patterns('',
#other commented code here
(r'^catalog/$', 'preview.views.home'),
)
To this (just removing the + before patterns):
urlpatterns = patterns('',
#other commented code here
(r'^catalog/$', 'preview.views.home'),
)
This is a minor thing but the CSS in the book doesn't include a style for the navigation, which means when you get to the screenshot it doesn't quite match.
I added this to the CSS to get the catalog page to match the screenshot:
#navigation{
background-color:#98ac5e;
}
Note that the full styles for the navigation do get added in a later step.
This is an issue I've run into numerous times when looking at older resources (e.g. this book was published in 2009) but building things with Django 1.4.
With Django 1.4 when you create a project, it automatically creates an application in the project with the same name as the project. I get the impression from the resources I've been looking at that this didn't used to be the case.
Point here is when you create your templates directory make sure it's underneath the ecommerce application directory, e.g. /.../ecommerce/ecommerce and not just /.../ecommerce
If after updating your settings.py
file to include this:
import os
# hack to accommodate Windows
CURRENT_PATH = os.path.abspath(os.path.dirname(__file__).decode('utf-8')).replace('\\', '/')
You get a template doesn't exist error, your templates are in the wrong place and need to be moved.
Also note that the comment # hack to accommodate Windows
refers only to the .replace('\\', '/')
bit at the end; even if you're on Linux you need the rest of that line in order to get around having to hard code the template path.
In this section an {% include %}
reference in purposely entered incorrectly so as to throw an error, with the goal being that you then check the djangodblog tables in MySQL to see how the error gets stored in the database.
This isn't working for me -- when I ran syncdb
it created the correct djangodblog tables in MySQL, but when errors occur they're not getting logged.
I'm going to ignore it for now since that seems like a minor thing, and given the abandoned state of the project in relation to the potential version differences with what was current when it was abandoned vs. the version the book may have been using, it might take a bit of work to figure out what's going on here.
If I get motivated enough I'll read the djangodblog docs and update this information accordingly.
Minor thing here that's addressed in the field-by-field discussion that follows, but in the code listing for the Category model the unique=True
constraint is not included for the name
field.
Another minor discrepancy between the full code listing here and the field-by-field discussion that follows. In this case in the full code listing the ordering specified in the Meta
class is ordering = ['-created_at']
whereas later when the Meta
class is discussed in more detail, the ordering is ordering = ['name']
Ran into incompatibility problems at this point related to djangodblog, specifically the error:
ImportError at /admin/
No module named filterspecs
I restarted the server with the --traceback
option (i.e. python manage.py runserver --traceback
) and that gave me the info indicating that the error is coming from djangodblog/admin.py
Rather than continue to mess with a version of djangodblog that isn't compatible with Django 1.4.1, I removed djangodblog:
sudo pip uninstall django-db-log
Also be sure and remove the 'djangodblog',
line from INSTALLED_APPS
in settings.py
, and the 'djangodblog.middleware.DBLogMiddleware',
line from MIDDLEWARE_CLASSES
in settings.py
.
Lastly, don't get too cavalier with uncommenting things in the INSTALLED_APPS
section of settings.py
. Since there are new things in there since this book was published and at one point the instructions are basically to uncomment everything, be aware that you need to leave these two items commented out to avoid errors at this stage of building the app:
- django.contrib.sites
- django.contrib.staticfiles
Note that the django.conf.urls.defaults
package is deprecated, so use django.conf.urls
instead.
In the code listing for the show_cart
function in cart/views.py
the following line:
cart_item_count = cart.cart_item_count(request)
Needs to be changed to the following since cart_item_count
doesn't exist in cart.py
:
cart_item_count = cart.cart_distinct_item_count(request)
Note the following comment in the cart.py
code:
import decimal # not needed yet but we will later import random
When trying to use the Add to Cart form you will get this error:
NameError at /product/les-paul/
global name 'random' is not defined
To resolve this, below import decimal
add the line to import random:
import random
Beginning with Django 1.2 a cross-site request forgery (CSRF) token was added to protect against CSRF attacks.
If you get the error CSRF token missing or incorrect
when trying to use the Add to Cart form, go to templates/catalog/products.html
and add this line between the <form>
tags:
{% csrf_token %}