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 8411385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:24:35+00:00 2026-06-10T00:24:35+00:00

i created a form to save a post into db for my blog project.

  • 0

i created a form to save a post into db for my blog project. I’ve designed index page. now i am tryin to create a form to create new posts. before that i was using ‘ manage.py shell’

here is my view :

def addpost(request):
    form = addForm()
    if request.method=="POST":
        titleform = request.POST['title']
        bodyform = request.POST['body']
        checkform = request.POST['isdraft']
        if form.is_valid():
                n = Post(title = titleform, body = bodyform, isdraft=checkform)
                n.save()

                return HttpResponseRedirect('/admin/')
    else:
        pass
    return render(request,'userside/add.html',{'form':form,})

my model.py:

class Post(models.Model):
    title = models.CharField(max_length = 100)
    body  = models.TextField()
    slug = AutoSlugField(populate_from='title',unique=True)
    posted = models.DateField(auto_now_add=True)
    isdraft = models.BooleanField()
    def __unicode__(self):
        return self.title

    @permalink
    def get_absolute_url(self):
        return ('view_blog_post',None, {'postslug':self.slug})

class addForm(forms.Form):
    title = forms.CharField(max_length=100)
    body  = forms.CharField(widget=forms.Textarea)
    isdraft = forms.BooleanField()

if i submit form as ‘isdraft’ field is False(unchecked) ; it gives error like:

MultiValueDictKeyError at /admin/addpost/

“Key ‘isdraft’ not found in “

and if i submit the form as ‘isdraft’ field is True(checked) ; it gives nothing. just refreshing form. no adding data into db.

i am doing sth wrong..

thank you

edit : Dmitry Beransky’s answer worked for checkbox error. but it still doesnt add any data into db. just refreshes the form.

  • 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-10T00:24:36+00:00Added an answer on June 10, 2026 at 12:24 am

    The whole point of using a form is that it takes care of validation and cleaning, that is converting values to the proper data types. That’s why you should be accessing form.cleaned_data rather than reques.POST, and you should be doing it inside the if form.is_valid() check.

    Edit

    I’ve just noticed that you’re never passing request.POST to the form. So form.is_valid() will never be true.

    Please go back and read the documentation about using a form in a view.

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

Sidebar

Related Questions

When I insert a new text_area input(created by rails) into an existing form with
new.html.erb <h3>Add post</h3> <%= form_tag :controller=>'posts', :action=>'create' do %> <%= label :q, :Title %>
I try to create a form that can save a person's form data so
I have created form using ModelForm but its not saving data into database. views.py
I'm using Pinax to create a new project. For this project I needed to
I would like to create form with text_fields TITLE CONTENT TAGS I have Post
echo $this->Form->create('Comment', array('url'=>array('controller' => 'comments', 'action' =>'add', $listposts['Post']['id']) ) ); echo $this->Form->input('post_id',array('type'=>'hidden','style'=>'width:30%','value'=>$listposts['Post']['id'])); echo $this->Form->input('name',array('style'=>'width:30%'));
So I brought the django-polls tutorial into a simple blog. Some posts have polls
For some reason, the form I created inserts data into the db on localhost.
I've created a page that requires a session variable which will be inserted into

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.