Gaby Solis
Gaby Solis

Reputation: 2587

Custom Tags in Django 1.2 with Google App Engine Python 2.7

Creating a custom tag in Google App Engine Python2.5 with Webapp used to be a joyful experience. Here: Django templates and variable attributes

But now, in Python 2.7 with Webapp2 and Django 1.2, it is a pain in the ass. I can only find bits of information here and there, and some of the methods contradict with each other.

The method described in http://www.john-smith.me/Tag/webapp2 ranks high in Google, but some people claim it is "what a waste of time" Webapp2 custom tags

This one method seems to work

from django.template.loader import add_to_builtins
add_to_builtins('xxxxx')

But I dont know the details. Who can provide a step by step example?

I dont know why there are no official documents about these stuff. I mean, this is not science experiments in which we explore the unknown. There supposed to be some documentation so the developers can save their time.

Upvotes: 3

Views: 385

Answers (1)

Marcin Trofimiuk
Marcin Trofimiuk

Reputation: 53

I had same problem.

The fix:

  1. Create templatetags folder. Add there module with custom tags as explained in Django docs Custom template tags and filters. Example folder structure:

    app.yaml  
        myapp/
            __init__.py
            templatetags/
               __init__.py
               my_tags.py
    
  2. In settings.py set INSTALLED_APPS to myapp (name of folder which contains templatetags sub-folder):

    INSTALLED_APPS = ( 'myapp' )
    
  3. Now when you call {% load my_tags %} in template Django should also seek the mytags module in myapp/*/templatetags/ folder.

Upvotes: 1

Related Questions