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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:49:26+00:00 2026-06-07T05:49:26+00:00

Motivation I’m currently creating a to-do-list app in django for practice. What I’m trying

  • 0

Motivation

I’m currently creating a to-do-list app in django for practice. What I’m trying to do now is to give the “user” the option to submit multiple to-do items at once. To do so, I display the form multiple times and then retrieve the items from each form individually.

Attempt & Error

Here’s the form in question:

class AddItemForm(forms.Form):
    name = forms.CharField(max_length=60, label='Item Name')
    priority = forms.IntegerField(required=False,
            widget=forms.Select(choices=Item.PRIORITY))
    due_date = forms.DateTimeField(required=False, label='Due Date')

However, when I try to create a form using keyword arguments (the lines of interest are in the for loop):

def add_item(request):
    if request.method == 'POST':
        r = request.POST
        names = r.getlist('name')
        priorities = r.getlist('priority')
        due_dates = r.getlist('due_date')
        for i in xrange(len(names)):
            form = AddItemForm(
                       name=names[i],
                       priority=priorities[i],
                       due_date=due_dates[i],
                   )
            if form.is_valid():
                item = form.cleaned_data
                Item.objects.create(**item) 
        return HttpResponseRedirect('/todo')

    form = AddItemForm()
    try:
        num_items = xrange(int(request.GET.get('n', 1)))
    except ValueError:
        num_items = xrange(1)
    return render(request, 'add_item.html', 
            {'form': form, 'num_items': num_items})

I get the following error message:

Exception Type: TypeError
Exception Value:    
__init__() got an unexpected keyword argument 'priority'

I don’t understand what’s going on since I do have priority as a field in AddItemForm.

HTML

Here’s the template html if it helps:

<!DOCTYPE html>
<html>
  <head> <title>Add item</title> </head>
  <body>
    <form method="post">{% csrf_token %}
      {% for i in num_items %}
        <div>{{ form }}</div>
      {% endfor %}
      <input type="submit">
    </form>

    <br><br>
    <form action="/todo" method="get">
      <input type="submit" value="Go back to To-Do List">
    </form>
  </body>
</html>
  • 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-07T05:49:27+00:00Added an answer on June 7, 2026 at 5:49 am

    Well, that’s not how forms work. You’re not supposed to process the POST arguments first, and you can’t pass data for individual fields as arguments like that. You’re simply supposed to pass request.POST into the form instantiation as-is.

    The way to do a set of multiple identical forms is to use a formset. You can then pass the POST data straight into the formset instantiation, and get validated forms out.

    Note that since your form is being used to create model instances, you may want to consider using a modelform (and a model formset, on the same page).

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

Sidebar

Related Questions

Can someone give me a good explanation on the motivation and application of JTA
I'm interesting with statistic and motivation of using task list in VS. Why are
My main motivation for trying to do this is to get Javascript that is
My motivation for trying out git-svn is the effortless merging and branching. Then I
Is it possible to change the conflict markers to something user defined? Motivation: It
We are currently running rails 2.1. My main motivation for the upgrade is the
Motivation : I often want to paste the results of a quick analysis using
Motivation To utilize Selenium's CSS selector mechanism alongside with CSS attribute selectors and the
(Motivation: Consider a problem where you have to select a sports team from a
Motivation: I have fxcop integrated in the build process, which makes fxcopcmd.exe run each

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.