Reputation: 2000
From commandline, I'm using this to convert a string to html:
>>>import markdown
>>> mk = Markdown()
>>> html = mk.convert(my_string)
and it gets me the html string without any errors, however when using the same in a module the django page prints an error as 'Global name 'markdown' not defined'
I cleared this out by using
import markdown
mk = markdown.Markdown()
html = mk.convert(my_string)
I'm a newbie and I need to know why the code which runs in the interpreter mode gives error when put inside a module. Does this mean whatever I try without errors in interpreter mode may probably bring error when wrote as code? Help
Upvotes: 1
Views: 7237
Reputation: 43
Solution suggested by Akansha worked to fix a similar problem
pip install django-markdown-deux
Upvotes: 0
Reputation: 95
Spent so many hours on this. Just do the following command, works for python3.6 and Django 2.0.5+ version.
pip install django-markdown-deux
Upvotes: 1
Reputation: 13105
The django docs weren't very clear about the fact you'd need to actually install something else to get this up. The only thing included by default from Django is the markup app to use markdown in templates, not in models.
Use the documentation here to install markdown and use this syntax:
http://packages.python.org/Markdown/reference.html
or
pip install markdown
or
easy_install markdown
Upvotes: 1
Reputation: 599610
That code as shown would not work in the interpreter. You must have previously run from markdown import Markdown
, or from markdown import *
.
Upvotes: 3
Reputation: 2722
Simply run:
import markdown
html = markdown.markdown(my_string)
If this does not work, it would help for us to see the actual error traceback.
Upvotes: 2