Dimitris Kougioumtzis Blog About technology

Pass request get items to a form class in django

Category Django

Posted on Sept. 22, 2018



Pass request get items to a form class in django


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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

About

My name is Dimitris Kougioumtzis and i work as a Web developer at Rapidbounce Company

Elsewhere