Joe Lewis
Joe Lewis

Reputation: 2000

Error while using Markdown with Django

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

Answers (5)

Jay
Jay

Reputation: 43

Solution suggested by Akansha worked to fix a similar problem

 pip install django-markdown-deux 

Upvotes: 0

Akansha Jain
Akansha Jain

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

Adam Grant
Adam Grant

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

Daniel Roseman
Daniel Roseman

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

Paragon
Paragon

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

Related Questions