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

  • Home
  • SEARCH
  • 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 6792713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:00:19+00:00 2026-05-26T18:00:19+00:00

I have made a model for a post and have to make a form

  • 0

I have made a model for a post and have to make a form to accept that post. I am using the below given view for generating a form both for making a new one and editing one, if it exists.

If the post exists then there will be a valid post_id and I will pick the correct post object and display the form with the fields filled, but if there is no post_id then I will generate a new blank form.

However I am getting an error

  • post_form() takes exactly 2 arguments (1 given)

What am I doing wrong?

def post_form(request,post_id):

    context_instance=RequestContext(request)

    if post_id:
        post = get_object_or_404(Post, pk=post_id)    
    else:
        #if the user is authenticated then pass the user object
        if request.user.is_authenticated():    
            post = Post(creator=request.user)
        else:
            post = Post()

    if request.method == 'POST':        
        if 'save' in request.POST:
            form = PostForm(request.POST, instance = post)
            if form.is_valid():
                form.save()
                return redirect(post)

    # Instantiate an empty form with the given user          
    else:
        form = PostForm(instance = post)

    return render_to_response('forum/post.html', {'form':form}, context_instance)
  • 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-05-26T18:00:20+00:00Added an answer on May 26, 2026 at 6:00 pm

    looks like you need a default value for post_id

    def post_form(request, post_id=None):
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a model using Sketchup, and have tested rendering it using Blender
I have comment model that references (foreign key) a post model and there is
I have a VERY simple C# Winforms project that I made using Visual Studio
I have made a data model, and now I've made a 2nd version. All
I have a package that I just made and I have an old-mode that
I have made a new windows service which works fine using barebone code (just
I have made a class which a form can inherit from and it handles
I have made a simple Rails application that allows people to comment on posts.
Quick question about CI. I have a view with a form, several text input
DUPLICATE: Using a Django custom model method property in order_by() I have two models;

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.