简体   繁体   中英

Retrieving form data after setting initial value

I wanted to populate my form fields with initial data, so I've set my view just like recommended by @ars in this question :

def update_member(request):
    if request.method == 'POST':
        urn = 'urn:publicid:myurn'
        member = Member(urn=urn)
        retrieved_members = member.search_member(filter_params=['urn', 'first_name', 'last_name'])

        # If search returns member
        if retrieved_members != []:
            member = retrieved_members[0]
            member_attributes = {'first_name': member.first_name, 'last_name': member.last_name}

            form = UpdateMemberForm(initial=member_attributes)

And it works properly. But when I manually fill in the fields in the template, my view still sets those initial values. I cannot reset the values as the ones passed via POST method. I know this happens because of the way I set the initial values, but I don't know how I could fix it.

Does anyone has an idea of how I could solve this?

如果检查POST数据中提交的值,则可以在调用UpdateMemberForm()之前使用这些值更新member_attributes。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM