librelist archives

« back to archive

How to add fields to a request?

How to add fields to a request?

Jean Jordaan
2015-04-10 @ 11:36
Hi all

I posted the following to as

I have a login page. Upon submission if 'webmail' is selected, the request
should be redirected to the webmail server, with the credentials submitted but
under different keys. Here's what I'm trying now:

    if form.validate_on_submit():
        if == 'webmail':
            return redirect('', code=307)

This almost works: the POST is redirected to webmail. However the values
submitted are the default values, not the assigned values.

I have some more issues though:

- the keys should be _user and _pass, but Flask seems to blow up with
  leading-underscore field names.

- I do not want to add these fields to the original class. I want to subclass
  upon submission, somewhat as follows:

    if form.validate_on_submit():
        if == 'webmail':
            class WebmailLoginForm(LoginForm):
                rc_user = EmailField('user',
            form = WebmailLoginForm(request.form)
            return redirect('', code=307)

When I do this, the added fields are not submitted.

I also tried messing with `request.form` (e.g. replacing the ImmutableDict with
my dict), but so far that hasn't worked either.

jean                                              . .. .... //\\\oo///\\