How to use Django MarkUp template templates with the Google App Engine WebApp Framework

I am using the Google App Engine WebApp Framework, which works with Django templates. I am trying to use Django MarkUp filters and the instructions say:

  • Put django.contrib.markup in your INSTALLED_APPS
  • Loading markup in your templates with {% load markup%}
  • Filter any text with the appropriate filter: {{text | textile}}

My question is that I am using a webapp environment. I do not have INSTALLED_APP middleware. Does anyone know how I can load this module in webapp?

+3
source share
1 answer

Tag library setup:

Create a folder in the application directory , for example. customtags

__init__.py

customtags.py,

'customtags.py'

from google.appengine.ext import webapp
register = webapp.template.create_template_register()

main.py :

template.register_template_library('customtags.customtags')

, :

from google.appengine.ext.webapp import template 

:

:

@register.filter
def foobar(value):
    return value

:

{{ something|foobar }}

:

@register.simple_tag
def mysimpletag():
    print 'hello from the simple tag'

:

{% mysimpletag %}

:

@register.inclusion_tag('templates/menu.html')
def menu():
    items = db.GqlQuery('SELECT * FROM Pages')
    return {'items':items}

templte :

{% menu %}
+3

Source: https://habr.com/ru/post/1791377/


All Articles