How to use raw python code in a Django template?


In smarty templates you can use raw PHP code in a template by placing it within the "literal" template tag:


echo 'hello world';


How can you use raw python code in a Django template?

5/22/2011 12:53:41 AM

Accepted Answer

You can't, that's why you have to create custom template tag which runs the functionality. Here's more information on how to do that:

5/22/2011 12:56:19 AM

You cannot use python code in django template. This is by design, Django's idea of template is to isolate the presentation logic from the programming code.

Django documentation states :

Django’s template engine provides a powerful mini-language for defining the user-facing layer of your application, encouraging a clean separation of application and presentation logic

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow