tags:

views:

195

answers:

3

Hi all,

I am trying to enable markup app in django and added 'django.contrib.markup' to INSTALLED APPS and in my model i import it as "import markdown".. but when i go to db and try to add something, i always get importerror. i guess iit must be about app installation issue or am i missing something?

this is how i do it in models.py:

class Entry(...)
title = models.CharField(verbose_name="Title", max_length=255)
slug = models.SlugField(verbose_name="Slug")
content_markdown = models.TextField(verbose_name="Markdown Content",
                                    help_text="Use Markdown syntax here.")
content = models.TextField(verbose_name="Page content as HTML", 
                           help_text="You don't have to touch here.", 
                           blank=True, null=True)
date = models.DateTimeField(verbose_name="Date Published")
author = models.ForeignKey(User, verbose_name="Author")

def save(self):
    import markdown
    self.content = markdown.markdown(self.content_markdown)
    super(Page, self).save()

great thanks in advance..

+3  A: 

I think that adding the django.contrib.markup app to your project gives you the ability to {% load markup %} in your templates (see the official Django docs). I think you'll still need to install Markdown from PyPI to use it (sudo easy_install Markdown).

jgeewax
It's {% load markup %}, when then allows you to use the "|markdown" filter (among others). Otherwise this answer is correct.
Carl Meyer
+2  A: 

You also have to make sure you have Markdown for Python installed on your Python path for this to work.

Brian Neal
easy_install installs markdown to /home/[username]/bin directory. i use export PYTHONPATH=/home/[username]/bin/markdown to update my pythonpath. but i still get the No module named markdown error. what is that about then?
israkir
Are you using the development server or a production server? What happens if you try to import markdown from a django shell?
Brian Neal
i am using production server. by django shell, it works.i don't know why it didn't work with easy_install, but later on i installed the markdown lib downloading source code and setup it manually, then set the pythonpath again. then it worked.. thanks for help;)
israkir
Cool! (cough, cough) *accept answer*, (cough, cough)
Brian Neal
It's possible the user that was running your production server (e.g. apache) didn't have markdown on the python path it was using.
Brian Neal
Well, actually later on i found that the markdown lib was installed by easy_install did not install a markdown.py file in my host. It just installed a markdown file without any file extension. Because in many website I saw PYTHONPATH was referring to markdown.py file, I tried to install it manually. That's how I made it works;)
israkir
A: 

I have the very same problem as you had today. Your solution works, compile it from the source rather than using easy_install. But I still not satisfied with that answer, why easy_install not work? We know django shell server works, but not production server right? The solution is very simple, you must restart apache. I don't know why, but after you run service restart httpd (on centos), then the problem is gone.

enoch_qin