Answer the question
In order to leave comments, you need to log in
How to include django-threadedcomments?
Good afternoon, help me connect a package with tree-like comments to Django. https://github.com/HonzaKral/django-threadedcomments
Can't figure out how they work with Django. Do I need my own model for comments? There are already models in the source code of the package, and I can add them through the admin panel, they appear in the database. But I do not understand how to save the form with comments? Do I need a post handler for a form in views?
Here's what I did while reading the Readme:
1) Installed a package with comments via pycharm.
2) Added everything you need to settings.py in installed_apps
3) Added routing to urls.py:
urlpatterns = patterns('',
url(r'^comments/', include('django.contrib.comments.urls')),
url(
r'^blog/view/(?P<slug>[^\.]+).html',
'blog.views.view_post',
name='view_blog_post')
)
{% load threadedcomments_tags %}
{% render_comment_list for post %}
{% render_comment_form for post %}
{% get_comment_count for post as comment_count %}
<p>This post has {{ comment_count }} comments.</p>
def view_post(request, slug):
item = get_object_or_404(Post, slug=slug)
item.addViewed()
c = {
'post': item,
'breadcrumbs': breadcrumbs('blog.views.view_post', obj=item)}
c.update(csrf(request))
return render_to_response('blog/' + 'view_post.html', c)
<div class="form-comment" id="form-comment">
<form action="comments/postfree" method="post">{% csrf_token %}
{{ form.as_p }}{# just to keep the example simple. Consider using django-crispy-forms in real life #}
<p>
<input type="submit" value="Submit Comment"/>
<a href="#c0" id="cancel_reply">cancel reply</a>
</p>
</form>
</div>
Answer the question
In order to leave comments, you need to log in
I launched an archive with an example from github, the comments started working, in general I will deal with the source :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question