Pass request get items to a form class in django

Django -- Posted on Sept. 22, 2018

Pass request get items to a form class in django

              
                def initial_form(request, form):
    '''
    form is an instance of a form 

    '''
    form_init = {}
    if request.GET.items():
        try:
            parameters = request.GET.items()
        except KeyError:
            parameters = {}
        for key, value in parameters:
            for field in form.fields:
                if key == field:
                    form_init[key] = value
        form.initial = form_init
    return form
                  
   
            

Related Posts