Thursday 15 April 2010

django - TypeError using custom template tag -


Module object is not capable of calling using the following template tag:

projectname / controlpanel / templatetags / __init __. Py (empty file)

projectname / controlpanel / templatetags / md_to_html.py template from the Markdown Import MarketDown register. Template. Library () @ register.filter (name = 'to_html') def to_html (MD): Return Markdown (MD)

From my thoughts, I {'Campaign': Campaign} , campaign with a return example of the model textfield.

  & lt; Div class = "span8" id = "editor2" & gt; {{Selected_campaign.description | To_html}} & lt; / Div & gt;  

Add it to INSTALLED_APPS

  'django < / P> 
  Use {% load markup%}   

& lt; Div class = "span8" id = "editor2" & gt; {{Selected_campaign.description | Sign-out: "safe"}} & lt; / Div & gt;


Update:

django.contrib.markup has been deprecated in Django 1.5. Here is a simple replacement for the Markdown Filter. Remove

line 'django.contrib.markup', to INSTALLED_APPS

to create a template tag Step:

  • Add any templatetags folder to your app folder.
  • Inside the templatetags folder an empty file __init __. Py

    Add markup.py inside templatetags with these codes: django.utils.safestring import mark_safe import markdown As mkdn register = template.Library () @ register.filter DR markdown (value, smode = none): return mark_safe (mkdn.markdown (value, safe_mode = 'escape')) < / Div>

No comments:

Post a Comment