Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:58:55+00:00 2026-06-13T19:58:55+00:00

I have managed to call python functions from jinja2 by using custom filters, but

  • 0

I have managed to call python functions from jinja2 by using custom filters, but I can only seem to call functions with one or more parameters. In the following I have had to pass a junk parameter in order to treat ctest as a function rather than a variable.

It also doesn’t work if I just call {{ ctest() }}.

Is there a different way to force this to be a function call or should I be using a different approach?

code:

def ctest(stuff):
    return "yeah!"

template_env = jinja2.Environment (loader = jinja2.FileSystemLoader(template_file_root))
#custom filters
template_env.filters['ctest'] = ctest

template:

Working? {{ junk|ctest }}

output:

working? yeah!
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:58:56+00:00Added an answer on June 13, 2026 at 7:58 pm

    Summarizing the comments into an answer:

    The ability to call functions by adding it to filters isn’t really the correct way of going about this since (as Wooble pointed out) I’m not looking to filter anything.

    Instead the function just needs to be added to the template_env.globals:

    template_globals.filters['ctest'] = ctest
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed to create a custom action in C# using MakeSfxCA which is
I have just managed to build my first C extension for Python, using Cython
I have managed to confuse myself whether I should return E_NOTIMPL or E_NOINTERFACE from
I have managed to set up Cassandra + Thrift and the Python wrapper for
I have been trying for months to get numpy installed for Python 3 but
I have been using the standard python that comes with OS X Lion (2.7.2)
I have Django 1.4.1 and Python 2.7 installed from ports on Mac OS X
Is it possible to call managed code, specifically IronRuby or IronPython from unamanaged code
I have: Python 2.6 Django 1.1.1 I downloaded Django-cms from git://github.com/digi604/django-cms-2.0.git I passed south
I have django-registration installed. I just updated my Python installation from 2.5 to 2.7.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.