Extending a base.html

Further digging into the templates of my website, I’ve tried setting up a base.html and using it to extend throughout the rest of my website. Seem to have a problem getting Django to find it though, because right now it says

base.html template does not exist

although it’s parked right next to all my other htmls in my templates/wagweb folder. hmm… reminds me of when static files were not loaded. Something is differently pointing wrongly!

{% static %} files

Now i’ve finally moved on to creating my own templates within django/wagtail. But first I have a bit of an issue with the static files.

When I attempt to add images in Wagtail,

Picture 12

I get the dreaded Internal Server Error

Internal Server Error
The server encountered an internal error or 
misconfiguration and was unable to complete 
your request.









Picture 11


Additionally, attempting to link to images in my static folder like so:

<p><img src="{% static "its_alive1.gif" %}" alt="Its Alive" /></p>

gives a broken image, although if I navigate to http://username.com/static/image.gif I can see the image in my browser.

Right now my settings.py are as follow:

MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/home/clarayee/website/static/'

The STATIC_URL is a hard-rooted to test if it makes any difference. Nope, no difference!


flock of migrating canada geese birds flying at sunset

Yes, migration! I would like some too! Who doesn’t love to travel?

PK Shiu has an amazing explanation of how South’s migration works here.

looking at my wagweb migrations, I realise:

from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
 # Adding model 'BlogPage'
 db.create_table(u'wagweb_blogpage', (
 (u'page_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['wagtailcore.Page'], unique=True, primary_key=True)),
 ('body', self.gf('wagtail.wagtailcore.fields.RichTextField')()),
 ('date', self.gf('django.db.models.fields.DateField')()),
 db.send_create_signal(u'wagweb', ['BlogPage'])


There’s BlogPage. Probably why BlogPage is working fine. But where’s my BlogIndexPage?

okay, time to make them migrate that:

[~/website/wagtailweb]# ./manage.py schemamigration wagweb --auto
 + Added model wagweb.BlogIndexPageRelatedLink
 + Added model wagweb.BlogIndexPage
Created 0002_auto__add_blogindexpagerelatedlink__add_blogindexpage.py. You can now apply this migration with: ./manage.py migrate wagweb


Following which I will follow instructions and migrate again:

Running migrations for wagweb:
 - Migrating forwards to 0002_auto__add_blogindexpagerelatedlink__add_blogindexpage.
 > wagweb:0002_auto__add_blogindexpagerelatedlink__add_blogindexpage
 - Loading initial data for wagweb.
Installed 0 object(s) from 0 fixture(s)





I swear BMO is shouting DJANGO in her heart.




Table Errors

I am no longer getting the Template errors when I click ‘View Live’ although I haven’t done anything in the pass few days. Sometimes I swear my computer does stuff on its own while I’m away.


Right now, Blog Page works, Root Page works. I can publish, save drafts and preview for both.

I’m only getting errors with Blog Index Page.

When I attempt to Publish Blog Index Page I get error

Picture 10

Exception Type: OperationalError at /admin/pages/new/wagweb/blogindexpage/2/
Exception Value: no such table: wagweb_blogindexpage


Definitely something to do with my SQlite database right? It’s probably a wrong path somewhere which is causing my SQlite to not find the table.

If i run manage.py migrate from shell,

 raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
django.core.exceptions.ImproperlyConfigured: ImportError treebeard: No module named treebeard

Oops! I think I saw this before. So that wasn’t resolve then.

I’m going to very simple try a pip install django-treebeard

running manage.py migrate this time gives me

 File "/home/clarayee/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 450, in execute
 return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table "wagweb_blogpage" already exists

wagweb_blogpage is working fine. I’m not sure why it’s still trying to create a new table for that?

But trying to save draft in my dashboard still returns error no such table.

I’m going to ./manage.py migrate wagweb again to update the database and see if it changes anything.

Running migrations for wagweb:
- Nothing to migrate.
 - Loading initial data for wagweb.
Installed 0 object(s) from 0 fixture(s)

Nothing updated. Error still there. Am reading up on migrations now.




Errors in Wagtail templates

AttributeError at /admin/pages/2/

type object 'BlogIndexPage' has no attribute 'related_links'
Exception Type: AttributeError
Exception Value:
type object 'BlogIndexPage' has no attribute 'related_links'

Hmm… something must be off with my templates. I get this error when I try to access my main page from explorer.

When I click ‘View Live’ on my main page from the dashboard I then get:

TemplateDoesNotExist at /test/



Request Method: GET
Request URL: http://username.co/test/

TEST is a virtual env directory I found in my cpanel after hosting helped with the installation of lxml in python2.7. It’s strange though, that the request URL is pointing to the TEST virtualenv which is in python2.6

Furthermore, when I try to Save Draft or Publish a Blog_Index_Page I get a wagtail error without traceback:

Picture 9

lxml installed, no attribute error again!

So my hosting has very kindly installed lxml for Python 2.7 for me.

That fixed my problem of having a mismatched version error and the error with no tree builder found.


There is however, still an error with my BlogPageIndex having an AttributeError that only shows up as ‘cannot save draft due to errors’ on my Wagtail interface.

also had the embarrassment of pronouncing Django wrong in a conversation. That quite possibly caused me Internal System Error with missing module ‘shy’.


RuntimeWarning: compiletime version 2.6 of module ‘lxml.etree’ does not match runtime version 2.7


Trying to make sure my bs4 (Beautifulsoup 4) and lxml are properly installed. They are in my system packages but as lxml is installed in python2.6, it does seem like I cannot use it properly with my Python2.7 environment.

Will need hosting to help sort this out for me since I cannot install lxml myself!


>>> import bs4
bs4/builder/_lxml.py:9: RuntimeWarning: compiletime version 2.6 of module 'lxml.etree' does not match runtime version 2.7
from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "bs4/__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "bs4/builder/__init__.py", line 317, in <module>
from . import _lxml
File "bs4/builder/_lxml.py", line 9, in <module>
from lxml import etree
File "lxml.etree.pyx", line 167, in init lxml.etree (src/lxml/lxml.etree.c:192356)
TypeError: encode() argument 1 must be string without null bytes, not unicode


In the process of removing the AttributeError in my Wagtail admin page, I added ‘django_libsass’ to my INSTALLED_APPS* in settings.py


Now I’m in admin and trying to create a basic blog, but bumped against 

FeatureNotFound at /admin/pages/new/wagweb/blogpage/2/

Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

Wagtail uses their own tree builder called django-treebeard. The app is installed and can be found in my directory within Wagtail >  Vendor. 

Will try to list it under INSTALLED_APPS and see if it works.

Nope it doesn’t work.

*(correction I have removed django_libsass and nothing broke, so I’m leaving it that way to reduce unnecessary fluff)


Ain’t no flock of birds.

So if we’ve been following spapas’ tutorial on how to set-up Wagtail, we will also know how to do a syncdb and migrate

Now that my Wagtail dashboard is finally up, I can move on to the next step in the tutorial. Adding a blog page.

Bump! Migration draws up Not Synced (use migrations) on my wagtails and taggit. But running the usual manage.py migrate returns

— nothing to migrate


1. Use schemamigrate

2. Wait patiently for changes to catch up?


This means I’d use South to handle the migration. Like in this answer by running

python manage.py schemamigration --initial wagweb

This returns:

The error was: table "wagweb_blogpage" already exists
 ! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had 
 ! to leave it in an interim state between migrations.


This means I shouldn’t be using South for migration in this format since Wagtail is already handling that.

Despite this error, I have now refreshed my Wagtail dashboard again and notice that my blogpage template is indeed in!

Maybe I should use solution #2.