<div dir="ltr">Actually, you can't. Writing the code fragment you've shown results in an exception. The key in the immutable dict is actually a <span style="background-color:rgb(255,255,0)">key</span> <i>AND</i> <span style="background-color:rgb(0,255,255)">value</span> pair:<div><br></div><div>ImmutableMultiDict([(<span style="background-color:rgb(255,255,0)">'{"nonstringify":"Cl","stringy":</span><span style="background-color:rgb(0,255,255)">"foo"</span><span style="background-color:rgb(255,255,0)">}</span><span style="background-color:rgb(238,238,238)">'</span>, '')])<br></div><div><br></div><div>If I ask for the keys for this object, I get:</div><div><br></div><div>['{"first_name":"asdfasdf"}']<br></div><div><br></div><div>Which doesn't make sense to me how I get this extra level of indirection...</div><div><br></div><div>Thanks,</div><div><br></div><div>-Clint</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 31, 2018 at 9:22 PM, Gergely Polonkai <span dir="ltr"><<a href="mailto:gergely@polonkai.eu" target="_blank">gergely@polonkai.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hello,</p>
<p dir="ltr">request.form is an ImmutableMultiDict. You can simply subscript it like</p>
<p dir="ltr">first_name = request.form['first_name']</p>
<p dir="ltr">given the name of the HTML form field is first_name. No to_dict() or other black magic is needed (well, not unless you have multiple fields with the same name).</p>
<p dir="ltr">Best,<br>
Gergely</p>
<br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Thu, Feb 1, 2018, 01:19 Clint Olsen <<a href="mailto:clint.olsen@gmail.com" target="_blank">clint.olsen@gmail.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi:<div><br></div><div>I should probably add that before I tried messing around with decoding the form, I just blurted out the object on the receiving side and got:</div><div><br></div><div></div></div><div dir="ltr"><div><div><font face="monospace, monospace" size="1">from flask import Flask, request, send_file</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">app = Flask(__name__)</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">@app.route('/', methods=['GET', 'POST'])</font></div><div><font face="monospace, monospace" size="1">def index():</font></div><div><font face="monospace, monospace" size="1">    print('Request: %s' % request.method)</font></div><div><font face="monospace, monospace" size="1">    if request.method == 'POST':</font></div></div></div><div dir="ltr"><div><div><font face="monospace, monospace" size="1">        data = request.form #.to_dict()</font></div></div></div><div dir="ltr"><div><div><font face="monospace, monospace" size="1">        print('First name from form is %s' % data)</font></div><div><font face="monospace, monospace" size="1">        return 'OK'</font></div><div><font face="monospace, monospace" size="1">    else:</font></div><div><font face="monospace, monospace" size="1">        return send_file("static/index.html")</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">if __name__ == "__main__":</font></div><div><font face="monospace, monospace" size="1">    app.run(host='0.0.0.0', debug=True)</font></div></div></div><div dir="ltr"><div></div><div><br></div><div><font face="monospace, monospace">First name from form is ImmutableMultiDict([('{"non-<wbr>stringify":"asdfasdf"}', '')])</font><br></div><div><br></div><div>So, even prior to attempt digging the info out of this structure I see the issue.</div><div><br></div><div>Thanks,</div><div><br></div><div>-Clint</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 29, 2018 at 4:52 PM, Clint Olsen <span dir="ltr"><<a href="mailto:clint.olsen@gmail.com" target="_blank">clint.olsen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi:<div><br></div><div>I'm new to Flask and Angular and only done a little web-based programming, so please forgive my lack of understanding. I've just cobbled together examples from Flask as well as some examples online to come up with the following.</div><div><br></div><div>I am interested in the most basic functionality of modifying a web form and capturing that in the back-end to prove I can get data at least in one direction:</div><div><br></div><div><u>static/app.js</u>:</div><div><font size="1"><br></font></div><div><div><font face="monospace, monospace" size="1">var app = angular.module('myApp', []);</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">app.controller('formCtrl', function($scope, $log, $http) {</font></div><div><font face="monospace, monospace" size="1">    $scope.firstName = "John";</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">    $scope.SendData = function () {</font></div><div><font face="monospace, monospace" size="1">        var data = { 'foo': $scope.firstName };</font></div><div><font face="monospace, monospace" size="1">        </font></div><div><font face="monospace, monospace" size="1">        var config = {</font></div><div><font face="monospace, monospace" size="1">            headers : {</font></div><div><font face="monospace, monospace" size="1">                'Content-Type': 'application/x-www-form-<wbr>urlencoded;charset=utf-8;'</font></div><div><font face="monospace, monospace" size="1">            }</font></div><div><font face="monospace, monospace" size="1">        }</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">        $http.post('/', data, config)</font></div><div><font face="monospace, monospace" size="1">            .success(function(results) {</font></div><div><font face="monospace, monospace" size="1">            $log.log(results);</font></div><div><font face="monospace, monospace" size="1">        })</font></div><div><font face="monospace, monospace" size="1">        .error(function(error) {</font></div><div><font face="monospace, monospace" size="1">            $log.log(error);</font></div><div><font face="monospace, monospace" size="1">        });</font></div><div><font face="monospace, monospace" size="1">    };</font></div><div><font face="monospace, monospace" size="1">});</font></div></div><div><br></div><div><u>static/index.html</u>:</div><div><br></div><div><div><font face="monospace, monospace"><!doctype html></font></div><div><font face="monospace, monospace"><html></font></div><div><font face="monospace, monospace">    <head></font></div><div><font face="monospace, monospace">        <script src="<a href="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js" target="_blank">https://ajax.googleapis.<wbr>com/ajax/libs/angularjs/1.5.3/<wbr>angular.min.js</a>"></script></font></div><div><font face="monospace, monospace">                <script src="<a href="http://code.angularjs.org/1.5.3/angular-route.min.js" target="_blank">http://code.angularjs.<wbr>org/1.5.3/angular-route.min.js</a><wbr>"></script></font></div><div><font face="monospace, monospace">                <script src="/static/app.js"></script></font></div><div><font face="monospace, monospace">                <link rel="stylesheet" href="/static/style.css" /></font></div><div><font face="monospace, monospace">    </head></font></div><div><font face="monospace, monospace">    <body> </font></div><div><font face="monospace, monospace">        <div ng-app="myApp" ng-controller="formCtrl"></font></div><div><font face="monospace, monospace">        <form></font></div><div><font face="monospace, monospace">            First Name: <input type="text" ng-model="firstName"></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">            <button data-ng-click="SendData()"></font></div><div><font face="monospace, monospace">                Send</font></div><div><font face="monospace, monospace">            </button></font></div><div><font face="monospace, monospace">        </form></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">        <h1>You entered: {{firstName}}</h1></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">        <div></font></div><div><font face="monospace, monospace">    </body></font></div><div><font face="monospace, monospace"></html></font></div></div><div><br></div><div><u>app.py</u>:</div><div><br></div><div><div><font face="monospace, monospace">from flask import Flask, request, send_file</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">app = Flask(__name__)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">@app.route('/', methods=['GET', 'POST'])</font></div><div><font face="monospace, monospace">def index():</font></div><div><font face="monospace, monospace">    print('Request: %s' % request.method)</font></div><div><font face="monospace, monospace">    if request.method == 'POST':</font></div><div><font face="monospace, monospace">        data = request.form.to_dict()</font></div><div><font face="monospace, monospace">        print('First name from form is %s' % data) </font></div><div><font face="monospace, monospace">        return 'OK'</font></div><div><font face="monospace, monospace">    else:</font></div><div><font face="monospace, monospace">        return send_file("static/index.html")</font></div><div><font face="monospace, monospace">        </font></div><div><font face="monospace, monospace">if __name__ == "__main__":</font></div><div><font face="monospace, monospace">    app.run(host='0.0.0.0', debug=True)</font></div></div><div><br></div><div>This code (sort of) works, but the message I get from index() is kind of weird, so maybe I'm not packaging the data payload correctly? In this example I just populate the form with a "C":</div><div><br></div><div>Flask log:</div><div><br></div><div><div>Request: GET</div><div>127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /? HTTP/1.1" 200 -</div><div>127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/app.js HTTP/1.1" 200 -</div><div>127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/style.css HTTP/1.1" 200 -</div><div>Request: POST</div><div><span style="background-color:rgb(255,255,0)">First name from form is {'{"foo":"C"}': ''}</span></div><div>127.0.0.1 - - [29/Jan/2018 16:40:16] "POST / HTTP/1.1" 200 -</div></div><div><br></div><div>I'm not not quite sure why the key/value pair is embedded in a dictionary as the key with an empty value.</div><div><br></div><div>Any pointers would be much appreciated!</div><div><br></div><div>Thanks,</div><div><br></div><div>-Clint</div><div><br></div></div>
</blockquote></div><br></div></div></div><span class="">
______________________________<wbr>_________________<br>
Flask mailing list<br>
<a href="mailto:Flask@python.org" target="_blank">Flask@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/flask</a><br>
</span></blockquote></div>
</blockquote></div><br></div>