开发者

Import Error when use templatetags in Django

开发者 https://www.devze.com 2022-12-29 00:13 出处:网络
Well, when I\'m trying to use \'inclusion\' in Django, I met some confused problems that I can\'t solve it by myself.

Well, when I'm trying to use 'inclusion' in Django, I met some confused problems that I can't solve it by myself.

There is the structures for my project.

MyProject---
            App1---
                   __init__.py
                   models.py
                   test.py
                   urls.py
                   views.py
            App2---
                   ...
            template---
                       App1---
                              some htmls
                       App2---
                              ...
            templatetags---
                           __init__.py
                           inclusion_cld_tags.py
            manage.py
   开发者_JS百科         urls.py
            __init__.py
            settings.py

I have registered templatetags folder in the settings.py (Both in Installed APPS & TEMPLATE_DIRS). But when I want to use {% load inclusion_test %} in my html, it raise an exception like this:

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

I think there is nothing wrong with my import work, how can I do with that?

Thanks for help!

My django version: 1.0+ My Python version: 2.6.4


  1. The templatetags folder should live in the app folder:

            App1---
                   __init__.py
                   models.py
                   test.py
                   urls.py
                   views.py
                   templatetags---
                           __init__.py
                           inclusion_test.py
                              ...
    
  2. Did you registered the tag?

Example:

register = template.Library()   
@register.inclusion_tag('platform/templatetags/pagination_links.html')
def pagination_links(page, per_page, link):
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号