Help passing the url

32 views
Skip to first unread message

Luka Nik

unread,
Apr 6, 2020, 2:18:22 PM4/6/20
to django...@googlegroups.com
How can I alter this post_detail function:

def post_detail(request):

post = get_object_or_404(Post)
comments = post.comments.filter(active=True)
new_comment = None
if request.method == 'POST':
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
new_comment = comment_form.save(commit=False)
new_comment.post = post
new_comment.save()
else:
comment_form = CommentForm()

return render(request, 'blog/post_detail.html', {'post': post,
'comments': comments,
'new_comment': new_comment,
'comment_form': comment_form
})


So this URL line can read the function?
path('post/<int:pk>/', views.post_detail, name='post-detail'),

Note:
In the Post model get_absolute_url is provided for returning the pk


Thanks in advance

ola neat

unread,
Apr 6, 2020, 3:42:02 PM4/6/20
to django...@googlegroups.com
You need to add the id as argument in the function 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMqindvdzOxxuZSC41Z%3D-TaQianws9jSDvZEevDLTgPw6mFPiw%40mail.gmail.com.

Luka Nik

unread,
Apr 6, 2020, 3:54:48 PM4/6/20
to django...@googlegroups.com

Irfan Khan

unread,
Apr 10, 2020, 5:16:58 AM4/10/20
to django...@googlegroups.com
Hi,
 
Need to pass id in function as parameter as well as in that post obj 


Reply all
Reply to author
Forward
0 new messages