def get_app_template_dir(app_name):
"""Get the template directory for an application
We do not use django.db.models.get_app, because this will fail if an
app does not have any models.
Returns a full path, or None if the app was not found.
"""
from django.conf import settings
from importlib import import_module
if app_name in _cache:
return _cache[app_name]
template_dir = None
for app in settings.INSTALLED_APPS:
if app.split('.')[-1] == app_name:
# Do not hide import errors; these should never happen at this point
# anyway
mod = import_module(app)
template_dir = join(abspath(dirname(mod.__file__)), 'templates')
break
_cache[app_name] = template_dir
return template_dir
评论列表
文章目录