Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use raw python code in a Django template?

Tags:

python

django

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

{literal}

echo 'hello world';

{/literal}

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

like image 366
Sammy Avatar asked May 22 '11 00:05

Sammy


People also ask

Where do you put Python code in Django?

Put your code in some directory outside of the document root, such as /home/mycode . These files are: The outer mysite/ root directory is a container for your project. Its name doesn't matter to Django; you can rename it to anything you like.

What does {{ name }} this mean in Django templates?

What does {{ name }} this mean in Django Templates? {{ name }} will be the output. It will be displayed as name in HTML. The name will be replaced with values of Python variable.


1 Answers

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:

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/

like image 94
rzetterberg Avatar answered Sep 19 '22 12:09

rzetterberg