1๐
โ
add this to INSTALLED_APPS
'django.contrib.markup',
copy markdown(http://pypi.python.org/pypi/Markdown) to your django project directory
then use
{% load markup %}
<div class="span8" id="editor2">
{{ selected_campaign.description|markdown:"safe" }}
</div>
Update:
django.contrib.markup
is deprecated in Django 1.5. Here is a simple replacement for the markdown filter.
remove line 'django.contrib.markup',
from INSTALLED_APPS
steps to create a template tag:
- add a folder
templatetags
in any of yourapp
folder. - inside
templatetags
folder add an empty file__init__.py
add markup.py
inside templatetags
with these codes:
from django import template
from django.utils.safestring import mark_safe
import markdown as mkdn
register = template.Library()
@register.filter
def markdown(value,smode=None):
return mark_safe(mkdn.markdown(value, safe_mode='escape'))
๐คsuhailvs
0๐
Well I do not why but markdown
seems does not work inside a function in django for example I typed this in django shell (python manage.py shell):
from markdown import markdown
def yes():
return markdown("YES")
and it gives me the next error:
NameError: global name 'markdown' is not defined
and this seems to work
def yes():
from markdown import markdown
return markdown("YES")
outside django shell the first method works correctly hope this helps!
- [Answer]-Django login failing after registration
- [Answer]-Feeding two ManyToManyFields of one QuerySet into HTML table columns
Source:stackexchange.com