How to fix the Django error displayed when loading Twissandra for the first time?

Twissandra is a beautiful example project that can be used to learn the features of Cassandra. Its maintained by ‘Tyler Thobbs’. Please see https://github.com/twissandra/twissandra for more details on the Twissandra project.

This article attempts to provide a solution for the Django error that is displayed when you complete all the steps listed at the Twissandra GitHub Readme document and attempt to visit the Twissandra site for first time. When I came across this issue for the firs time, a through research on the solution led me to the fix posted at :Tod (Play Cassandra).

Error reported by the web page:

Error importing template source loader django.template.loaders.filesystem.load_template_source: "'module' object has no attribute 'load_template_source'"

One of the possible solution:

  • Open the ‘settings.py‘ file in the folder which contains the extracted contents of the Twissandra project.
  • Search, ‘TEMPLATE_LOADERS=(‘ and within it, search, ‘django.template.loaders.filesystem.load_template_source‘. Comment this line and add, ‘django.template.loaders.filesystem.Loader‘.
  • Similarly, within ‘TEMPLATE_LOADERS=(‘, search, ‘django.template.loaders.app_directories.load_template_source‘, and replace it with, ‘django.template.loaders.app_directories.Loader‘.

Upon successfully performing the above operation, the updated ‘settings.py‘ in my machine looks like:

....

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    # 'django.template.loaders.filesystem.load_template_source',
    # 'django.template.loaders.app_directories.load_template_source',
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.load_template_source',
)

....

Explanation of the solution:

The code segment that we commented out performed Function based template loaders that were deprecated in Django v1.2 and were eventually removed in Django v1.4. But the Twissandra code still tried to load them. As a result, an exception was displayed when the Twissandra site was loaded for the first time in the browser.

As a fix, we updated the list of ‘TEMPLATE_LOADERS‘ in ‘settings.py‘ to utilize the class based loaders instead of function based loaders.

This has been fantabulous explained at: http://comments.gmane.org/gmane.comp.python.django.devel/31833.


References:

Advertisement

One thought on “How to fix the Django error displayed when loading Twissandra for the first time?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.