Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:55:30+00:00 2026-06-03T07:55:30+00:00

On my page, i need to display the post detail and a comment form

  • 0

On my page, i need to display the post detail and a comment form for viewer to post comment. I created 2 generic views:

# views.py
class PostDetailView (DetailView):
  model = Post
  context_object_name = 'post'
  template_name = 'post.html'

  def get_context_data(self, **kwargs):
    context = super(PostDetailView, self).get_context_data(**kwargs)
    context['comment_form'] = CommentForm()
    return context

class AddCommentView(FormView):
  template_name = 'post.html'
  form_class = CommentForm
  success_url = '/'

  def form_valid(self, form):
    form.save()
    return super(AddCommentView, self).form_valid(form)

  def form_invalid(self, form):
    return self.render_to_response(self.get_context_data(form=form))

detail = PostDetailView.as_view()
add_comment = AddCommentView.as_view()


# urls.py 
....
url(r'^(?P<pk>\d+)/$', view='detail'),
url(r'^(?P<post_id>\d+)/add_comment/$', view='add_comment'),

....

Error would occur in the AddCommentView,since I haven’t specified the post’s id for the comment. How can I access the post_id in the AddCommentView?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:55:31+00:00Added an answer on June 3, 2026 at 7:55 am

    self.kwargs['post_id'] or self.args[0] contains that value

    Docs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display the content of another page from a function using return.
I need to display the wall posts from Facebook page to another website's social
On page 1 of a mobile app I need to display categories from a
I have an asp.net mvc 2 app. I need to display the same page
I need to display all the pages on the one page. At the moment
Ive got some form validation on my page thats ment to display an error
I need to validate a form in php and display some error messages in
I have a page/gsp that displays 3 different classes. This means that I need
In my page I need to give my current variable as parameter to the
I have a PHP page I need to limit execution access of to only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.