Search code examples
pythondjangodjango-formsdjango-viewsdjango-formwizard

How to pass non default argument with default arguments in python django forms


Here is my code

class FarticlesWizard(FormWizard):

    def done(self,request,form_list):

        if request.method=='POST':
            form1=F1articles(request.POST)  
            form2=F2articles(request.POST)
            form_dict={}
            for x in form_list:
                form_dict=dict(form_dict.items()+x.cleaned_data.items())
                insert_db=Marticles(heading = form_dict['heading'],
                                    content = form_dict['content'],
                                    created_by=request.session['user_name'],    
                                    country=form_dict['country'],
                                    work=form_dict['work'])
                insert_db.save()
            return HttpResponseRedirect('/display/')

but i now i need to pass def done(self,request,id=None, form_list): where id is non default argument ...iam getting an error message non-default argument follows default argument (views.py, line 130) is there a way to do it?


Solution

  • No. As the error message suggests, any arguments with default values must come after all arguments without default values.

    Why do you feel you need to add the new argument in the middle like that? Why not just do def done(self, request, form_list, id=None)? Adding a new argument in the middle will break all existing code that calls the function with positional arguments.