Inspiration I'm currently making a to-do list I'm trying to do what I'm trying to do now, "user" has the option of submitting multiple to-do items at once. To do this, I display the form multiple times and then recover items individually from each form. Attempts & amp; Error Here is the question in question: However, when I try to create a form using keyword arguments (the lines of interest are in the loop): keyword logic 'priority' I do not understand that since I have priority running as a field in AddItemForm. HTML If this helps, the template is HTML: OK, this is not how forms work. You do not want to process POST arguments first, and you can not pass data for different fields as arguments of that type. You should simply pass in the initial form of How to set one of multiple simultaneous forms, after that you can pass POST data directly into the format installation, and get valid formatting. Note that since your form is being used to create a model form, you (and a model format, on the same page)
class addItemForm (forms.Form): name = forms.CharField (max_length = 60, label = 'item Name ') Priority = forms.IntegerField (Required = False, Widget = Form. Select (Option = Item Sponsor) due_date = forms.DateTimeField (Required = Incorrect, Label =' Due Date ')
def add_item (requested): If request.method == 'Post': R = Antoine . POST name = R.GetList ('name') preferences = R.GetList ('priority') reason_dates = rgetlist ('pay_date') i amrange (in lane (name)): form = addItemForm (name = name [i ], Priority = preferences [i], due_date = due_dates [i],) if form.is_valid (): item = form.cleaned_data Item.objects.create (** item) returns HttpResponseRedirect ('/ Todo') form = AddItemForm (Try: num_items = xrange (int (request.GET.get ('n', 1)) Exclude valueError: num_items = xrange (1) submit the return (request, 'add_item.html', {'form': I get the following error message: < / P>
Exception type: TypeError exception value: __init __ () has become unpredictable:
gt; & gt; & gt; & lt; html & gt; Top & gt; & Lt; Title & gt; Add item & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form method = "post" & gt; {% Csrf_token%} in {% i in num_items%} & lt; Div & gt; {{Form}} & lt; / Div & gt; {% Endfor%} & lt; Input type = "submit" & gt; & Lt; / Form & gt; & Lt; Br> & Lt; Br> & Lt; Form action = "/ todo" method = "get" & gt; & Lt; Input type = "submit" value = "return to to-do list" & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;
request.POST .
Comments
Post a Comment