views:

277

answers:

3

Hi,

I am trying to display Django source code from a Django template.. However, I cannot find a tag similar to HTML's pre or xmp.

Can someone point me to the right direction. Thanks

EDIT

Heres the code

Also, I have a block with the same name.. which springs the error

+1  A: 

If your view puts the source code in a context variable called source, your template might look like this:

<pre>
{{ source|escape }}
</pre>

The escape filter will escape certain characters to make sure the HTML is rendered correctly.

If you just want to display hard coded template source in your template, there are two options.

Use HTML escaping to do so and remove your XMP tags.

&#123; instead of }
&#125; instead of {

Or use the templatetag template tag:

{% templatetag openbrace %} instead of }
{% templatetag closebrace %} instead of {

etc.. refer to link

Andre Miller
I am not using a view ... just simple Django template which is supposed to show Django code from another template for demonstration.Also, I tried using <pre>.. it gives an error.. which means it is parsing the text within the pre tags.
Could you post your template and the context variables it has?
Andre Miller
Code pasted on external website
Ah, ok, I understand now. Answer updated.
Andre Miller
{% templatetag openbrace %} instead of }{% templatetag closebrace %} instead of {worked.. thanks
A: 

Hi, i don't really sure if i understand: If you want show django template code try change '{' and '}' to

&#123; and &#125;

After that django will not recognize it as var.

EDIT: another way to tell django not to parse code is here :) http://docs.djangoproject.com/en/dev/ref/templates/builtins/#templatetag

Rin
yes, this worked partially but since { is still under xmp tags.. its not displaying a curly brace but {
Check Edit :) (15 char nananaa.... )
Rin
your edit.. is it pointing towards.. comment tag.. that will simply ignore.. I want to display the code not ignore it completely
It will works, just replace {% to {% templateteg|openblock %} etc...
Rin
It will works, just replace {% to {% templateteg|openblock %} etc...
Rin
+1  A: 

Django has a special template tag for this purpose.

Stephen Van Dahm