Returning multiple values in a view using Flask (Python)
<p>I'm struggling to even understand this in my head from a broad point of view, but I'll try explain as best as I can, if anything isn't clear please comment asking for more information.</p>

<p>Right now I have a python function that fetches a users name and their user ID from an internal API in my workplace that is tied to the username of each worker, this is then routed to a web page with a table like so. (I use the username as the main way of retrieving the data, i guess it could be considered the primary key?)</p>

<pre><code>@app.route('/user/&lt;username&gt;')
def issue(username)

    json = get_json(username)

    _user = get_username(json)
    _id = get_id(json)

    print "User: " + _user
    print "ID: " + _id
</code></pre>

<p>(The <code>get_username()</code> and <code>get_id()</code> functions parse through the JSON file and retrieve the data that I need)</p>

<p>The way users get to this page is at the main page of the webapp there is a text field, they type in a username, it then redirects them to the page 127.0.0.1:5000/user/username , which in turn calls that function above. </p>

<p>This gives a very simple web page with just the username and the ID. However, how could I render multiple names and ID's with one request.</p>

<p>So for example:</p>

<pre><code>1. User goes to home page
2. User enters "John Doe, Harry Smith, Alex Boggs" into the text box and hit submit
3. They are then presented with this information

User: John Doe
ID: 127

User: Harry Smith
ID: 412

User: Alex Boggs
ID: 322
</code></pre>

<p>I'm not really sure where to even begin to do this, as I only really know how to pass one argument at a time. </p>

<p><strong>Note: Ideally the data wouldn't actually be tied to a URL, and instead would just generate below the search box on the homepage, but I will settle for any solution.</strong> </p>

<p>If user enters <code>John Doe, Harry Smith, Alex Boggs</code> in text box then you should get <code>John Doe, Harry Smith, Alex Boggs</code> in Flask and you have to split it <code>"John Doe, Harry Smith, Alex Boggs".split(", ")</code> to get list of names. </p>

<p>Now you can use <code>for</code> loop to print User, ID for every name.</p>

python flask views