Hi, Need to pass id in function as parameter as well as in that post obj
On Tue, 7 Apr 2020 at 1:23 AM, Luka Nik <[email protected]> wrote: > How do I pass it exactly? > > On Mon, 6 Apr 2020, 9:41 pm ola neat, <[email protected]> wrote: > >> You need to add the id as argument in the function >> >> On Mon, Apr 6, 2020, 19:17 Luka Nik <[email protected]> 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 [email protected]. >>> 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 [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAHLKn73Evou6KsXQGFNYA95AXPLjraaP_mXOTeYPsCOAobHY1w%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAHLKn73Evou6KsXQGFNYA95AXPLjraaP_mXOTeYPsCOAobHY1w%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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAMqindsi%2Be0eRwjST3r68rNUa%2B0qRc%2Behf6%2B8g66im7MUVq8Uw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAMqindsi%2Be0eRwjST3r68rNUa%2B0qRc%2Behf6%2B8g66im7MUVq8Uw%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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALKGVirHC%3Dmp3L0UZTeOrPFWug0pfP8_-P_Owsf%3D_KZAtA5xFg%40mail.gmail.com.

