문제

I'd like to add django-pagedown to my site's blog. I have a site, and an application called blog, built with Django, and I've implemented the built-in comments. These work just fine but I'm now trying to get django-pagedown to work in the comments. For example, if a user comments on one of my articles, I would like to be able to support markdown so users could comment with code snippets or formatting without using HTML (which I probably don't want to support).

I installed django-pagedown successfully with pip:

pip install django-pagedown

I added it to my INSTALLED_APPS section in settings.py and collected static files:

INSTALLED_APPS = (
    ...
    'pagedown',
    ...
)

python manage.py collectstatic

Something happened, because when I added this code to my blog/admin.py file the admin post preview window appeared:

...
from pagedown.widgets import PagedownWidget, AdminPagedownWidget
from django.db import models
....

class PostAdmin(admin.ModelAdmin):
    ...
    formfield_overrides = {
        models.TextField: {'widget': AdminPagedownWidget },
    }
    ...

Since I'm not very familiar with Django yet, the docs at:

https://github.com/timmyomahony/django-pagedown

aren't enough for me to fully understand how it's implemented. Basically, I want to add this functionality to the user comments section in the blog.

I'd like to be able to accomplish this without making custom forms and just using the built-in comments in Django. Is this possible?

I was able to get this working but ended up going with Disqus because it has great functionality and is simple to set up and moderate.

도움이 되었습니까?

해결책

First, consider carefully whether you really want to use django.contrib.comments; it's being deprecated in version 1.6 and will no longer be supported after that. See the discussion here.

If you do want to use it, you're going to have to customize the comments app. The documentation lays out what you need to do. In your forms.py you'll have something like this:

from pagedown.widgets import PagedownWidget
from django.contrib.comments.forms import CommentForm
from django.forms import CharField

class PagedownCommentForm(CommentForm):
    comment = CharField(widget=PagedownWidget())        

You'll also need to put a get_form() function in your new app's __init__.py, and make the other changes described in the docs.

Hopefully this will give you an idea of how to proceed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top