mirror of
				https://github.com/django/django.git
				synced 2025-10-30 09:06:13 +00:00 
			
		
		
		
	git-svn-id: http://code.djangoproject.com/svn/django/trunk@1379 bcc190cf-cafb-0310-a4f2-bffc1f526a37
		
			
				
	
	
		
			26 lines
		
	
	
		
			932 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			932 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| # Wrapper for loading templates from eggs via pkg_resources.resource_string.
 | |
| 
 | |
| try:
 | |
|     from pkg_resources import resource_string
 | |
| except ImportError:
 | |
|     resource_string = None
 | |
| 
 | |
| from django.core.template import TemplateDoesNotExist
 | |
| from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION
 | |
| 
 | |
| def load_template_source(template_name, template_dirs=None):
 | |
|     """
 | |
|     Loads templates from Python eggs via pkg_resource.resource_string.
 | |
| 
 | |
|     For every installed app, it tries to get the resource (app, template_name).
 | |
|     """
 | |
|     if resource_string is not None:
 | |
|         pkg_name = 'templates/' + template_name + TEMPLATE_FILE_EXTENSION
 | |
|         for app in INSTALLED_APPS:
 | |
|             try:
 | |
|                 return (resource_string(app, pkg_name), 'egg:%s:%s ' % (app, pkg_name))
 | |
|             except:
 | |
|                 pass
 | |
|     raise TemplateDoesNotExist, template_name
 | |
| load_template_source.is_usable = resource_string is not None
 |