Django自定义模板标签在Google App Engine中 [英] Django Custom Template Tags In Google App Engine

查看:146
本文介绍了Django自定义模板标签在Google App Engine中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在Google App Engine网路应用程式中加入以下标签:



http://www.djangosnippets.org/snippets/1357/



这个文件是否有任何配置让它与Google App Engine一起工作?



因为我遵循Django模板教程: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/



并具有以下结构:

  templatetags / 
__init__.py
range_template。在模板文件中,我有{%load range_template%}

$ b $($)$ / $ $ $ $ $ $ $ $ $ $ $
$ b

但是我收到错误:



TemplateSyntaxError:'range_template'不是有效的标记库:无法从django加载模板库。 templatetags.range_template,没有名为range_templa的模块te



另一件可能是为什么这不工作的问题是INSTALL_APPS settings.py文件。不知道如何配置它。



我的应用程序的根目录中有一个settings.py文件,其中包括:



INSTALLED_APPS =('templatetags')



任何建议将不胜感激。

解决方案

尝试执行以下操作:

  $ python ./manage.py startapp foo 

将foo添加到已安装的应用程序中:

 code> INSTALLED_APPS + =('foo',)

将您的模板标签目录移动到foo应用程序如下所示:

  ./ djangoproject 
__init__.py
settings.py
urls。 py
etc ..
foo /
__init__.py
templatetags /
__init__.py
range_template.py

Django约定是模板标签代码驻留在应用程序中,名为templatetags的目录(查看文档)。我认为GAE也是如此。


I am trying to include the following Tag In Google App Engine Web Application:

http://www.djangosnippets.org/snippets/1357/

Is there any configuration of this file to make it work with Google App Engine?

Cause I followed the Django Template tutorials: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/

and have this structure:

templatetags/
    __init__.py
    range_template.py

in the Template file, I have {%load range_template%}

But I am getting the error:

TemplateSyntaxError: 'range_template' is not a valid tag library: Could not load template library from django.templatetags.range_template, No module named range_template

The other thing that might be a problem why this ain't working is, the INSTALL_APPS settings.py file. Not sure how to configure it.

I have a settings.py file in the root of my application and included this:

INSTALLED_APPS = ('templatetags')

Any advice would be greatly appreciated.

解决方案

try doing the following:

$ python ./manage.py startapp foo

Add foo to installed apps:

INSTALLED_APPS += ('foo',)

And move your templatetags directory into your foo app. Something like:

./djangoproject
    __init__.py
    settings.py
    urls.py
    etc..
    foo/
        __init__.py
        templatetags/
            __init__.py
            range_template.py

Django convention is that template tag code resides in apps, in directories named templatetags (see docs). I assume the same would be true for GAE.

这篇关于Django自定义模板标签在Google App Engine中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆