English 中文(简体)
在将电话输入到父目录后, 我如何能让模板缓存在 Appengine 中?
原标题:How could I enable template caching in appengine after incorporating calls to parent directories?

当 Django 模板中的扩展标签无法在父目录中引用基准模板时, 我的问题就开始了。 此问题 < a href=" https:// stackoverflow.com/ questions/4994913/ app- engine- default- django- version- change > > 1 有一个很好的答案, 但是它禁用默认模板提供的隐性模板缓存。 render 函数在 Appengine 中 。

答案的作者还提到,实施这个模板缓存将相当简单,但我认为,改变这种功能将在今后产生虫子。 有什么建议吗?

最佳回答

我们所有的模板 dirs 都是一个模板 dir 的子文件夹, 所以我们只需要让装载器先查看那里。

但它并没有改变AFAICT的行为。

我们之所以这样做,是因为我们扩展了基础装载器,使用了这样的模块 option_path.py :

class Loader(filesystem.Loader):
"""
Looks for templates in an alternative path.

Allows a template to extend a template which is located in a specified views path.
"""

is_usable = True
__view_paths = None

def __init__(self, views_path):
    if Loader.__view_paths is None:
        Loader.__view_paths = [views_path]

def get_alternative_template_sources(self, template_name):
    for template_dir in Loader.__view_paths:
        try:
            yield safe_join(template_dir, template_name)
        except UnicodeDecodeError:
            # The template dir name was a bytestring that wasn t valid UTF-8.
            raise
        except ValueError:
            # The joined path was located outside of this particular
            # template_dir (it might be inside another one, so this isn t
            # fatal).
            pass

def get_template_sources(self, template_name, template_dirs):
    return itertools.chain(
        filesystem.Loader.get_template_sources(self, template_name, template_dirs),
        Loader.get_alternative_template_sources(self, template_name))

然后在同一模块中:

= 装载器

然后在 main. py 中:

def main():
    views_path = os.path.join(os.path.dirname(__file__),  templates )
    settings.TEMPLATE_LOADERS = (( web.rich.templates.alternative_path.Loader , views_path),
                              django.template.loaders.filesystem.Loader ,
                              django.template.loaders.app_directories.Loader )
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签