FAQ
I've got a fairly standard ListView trying to render a template stored in
my DB (originally via the dbtemplates lib, finally trying my own template
loader). However, the view times out in the browser. After some
investigation, it seems that Loader.load_template_source() is called 69
times in the process. Does anyone see an issue in my code or can you come
up with a reason why this is the case?

*visitor_index (db template)*
*
*

<!DOCTYPE html>
<html lang="en">
     <head>
         <title>{{ site.name }}</title>
     </head>
     <body id="home">
     <pre>
         Starting
         {% for video in videos %}
             {{ video.headline }}
         {% endfor %}
     </pre>
     </body>
</html>



*urls.py*

     from django.conf.urls import include, url
     from django.conf.urls.defaults import patterns
     from videos.views import *

     urlpatterns = patterns('',
         url(r'^$', VisitorIndex.as_view(), name='index'),
     )

*views.py*

     import logging
     from django.views.generic import ListView
     from videos.models import Video

     logger = logging.getLogger(__name__)

     class VisitorIndex(ListView):
         context_object_name = 'videos'
         template_name = 'visitor_index'

         def get_queryset(self):
             logger.debug('VisitorIndex.get_queryset()')
             return Video.on_site.filter(privacy_mode='PUB')

*loader.py*

     import logging
     from django.template import TemplateDoesNotExist
     from django.template.loader import BaseLoader
     from dbtemplates.models import Template

     logger = logging.getLogger(__name__)

     class Loader(BaseLoader):
         is_usable = True

         def load_template_source(self, template_name, template_dirs=None):
             try:
                 logger.debug('Loader.load_template_source(%s, %s)' %
(template_name, template_dirs))
                 template =
Template.on_site.get(slug__exact=template_name).template_body
                 logger.debug('Loaded template.')
                 return template, template_name
             except Template.DoesNotExist:
                 logger.debug('Template.DoesNotExist caught.')
                 raise TemplateDoesNotExist, template_name

*models.py*

     import logging
     from django.contrib.sites.models import Site
     from django.contrib.sites.managers import CurrentSiteManager
     from django.db import models

     logger = logging.getLogger('__name__')

     class Template(models.Model):
         slug = models.CharField(max_length=80)
         template_body = models.TextField()
         site = models.ForeignKey(Site)

         objects = models.Manager()
         on_site = CurrentSiteManager('site')

         def __unicode__(self):
             return self.slug

*settings.py*

     TEMPLATE_LOADERS = (
         'django.template.loaders.filesystem.Loader',
         'django.template.loaders.app_directories.Loader',
         'dbtemplates.loader.Loader',
     )

*app.log*

     2013-05-08 15:08:26,167 [DEBUG] dynamicsites.middleware: ENV_HOSTNAMES
lookup subdomain=None domain=mydomain.com domain_unsplit=mydomain.com
     2013-05-08 15:08:26,168 [DEBUG] dynamicsites.middleware: Checking
database for domain=mydomain.com
     2013-05-08 15:08:26,227 [DEBUG] dynamicsites.middleware: Using site
id=2 domain=mydomain.com
     2013-05-08 15:08:26,261 [DEBUG] videos.views:
VisitorIndex.get_queryset()
     2013-05-08 15:08:26,265 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,426 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:26,542 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,554 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,569 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,587 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,608 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,632 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,658 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,689 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,721 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,756 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,794 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,835 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,897 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,944 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:26,998 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,052 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,107 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,166 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,227 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,293 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,360 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,431 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,504 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,580 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,692 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,773 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,857 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:27,958 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,048 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,139 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,234 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,332 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,433 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,537 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,646 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,756 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:28,869 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:29,001 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:29,119 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:29,241 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:29,365 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:29,512 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:29,648 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:29,781 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:29,933 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:30,088 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:30,233 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:30,378 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:30,526 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:30,680 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:30,835 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:31,006 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:31,166 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:31,327 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:31,492 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:31,661 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:31,833 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:32,006 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:32,199 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:32,380 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:32,562 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:32,749 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:32,938 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:33,150 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:33,349 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:33,550 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:33,752 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:33,952 [DEBUG] dbtemplates.loader:
Loader.load_template_source(visitor_index, None)
     2013-05-08 15:08:33,954 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,954 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,955 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,955 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,956 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,956 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,957 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,957 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,958 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,958 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,959 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,959 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,960 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,960 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,960 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,961 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,961 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,962 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,962 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,963 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,963 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,964 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,964 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,965 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,965 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,966 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,966 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,966 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,967 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,967 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,968 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,968 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,969 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,969 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,970 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,971 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,971 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,972 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,972 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,972 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,973 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,973 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,974 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,974 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,975 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,975 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,976 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,976 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,977 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,977 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,978 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,978 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,979 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,979 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,980 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,980 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,981 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,981 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,982 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,982 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,983 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,983 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,983 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,984 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,984 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,985 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:33,985 [DEBUG] dbtemplates.loader: Loaded template.
     2013-05-08 15:08:37,663 [DEBUG] dynamicsites.middleware: ENV_HOSTNAMES
lookup subdomain=None domain=mydomain.com domain_unsplit=mydomain.com
     2013-05-08 15:08:37,663 [DEBUG] dynamicsites.middleware: Checking
database for domain=mydomain.com
     2013-05-08 15:08:37,693 [DEBUG] dynamicsites.middleware: Using site
id=2 domain=mydomain.com

Any help is much appreciated,
Wes


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedMay 9, '13 at 8:27p
activeMay 9, '13 at 8:27p
posts1
users1
websitedjangoproject.com

1 user in discussion

Wesley Kincaid: 1 post

People

Translate

site design / logo © 2022 Grokbase