You need to add the id as argument in the function

On Mon, Apr 6, 2020, 19:17 Luka Nik <luka2...@gmail.com> wrote:

> 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
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMqindvdzOxxuZSC41Z%3D-TaQianws9jSDvZEevDLTgPw6mFPiw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMqindvdzOxxuZSC41Z%3D-TaQianws9jSDvZEevDLTgPw6mFPiw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHLKn73Evou6KsXQGFNYA95AXPLjraaP_mXOTeYPsCOAobHY1w%40mail.gmail.com.

Reply via email to