djangoのdajaxテクノロジーによる投稿にコメントを追加したいのですが、これは機能しません。それについて私を助けてくれませんか、またはその例でdajaxを使用する方法をもう少し教えてください。
ajax.py
@dajaxice_register
def add_comment(request):
`if request.method == 'POST':
post_id = request.POST['post_id']
post_obj = Post.objects.get(id = post_id)
error = {}
iweb_obj = post_obj.topic.iweb
content = request.POST['content']
img = request.POST['img']
if len(content) == 0:
error[content] = 'Write something'
else:
new_comment = Comment(img=img, post=post_obj, content=content, author=request.user, pub_date=datetime.datetime.now())
new_comment.save()
comment = render_to_response('comment.html',{'comment':new_comment})
dajax = Dajax()
dajax.assign('#post-' +int(post_id)+ ' comments', innerHTML, comment)
return dajax.json() `
コメントを下に追加する必要があるHTMLの郵便番号。
table width="100%" id="post-{{ post.post.id }}"
投稿はこちら
ul class="comments"
{% include "comments.html" %}
/ul
/table
JSコードですが、comment_formは別のテンプレートにあります。
$('.comment_form form').submit(function() {
`var form = $(this);
if($('textarea', form).val().length > 1) {
Dajaxice.project.add_comment(Dajax.progress,{});
$('textarea', form).val('');
}
}
)});`