Adding a Second Text Area to a Flask App
Question: I have a simple flask app. I tried to add a second text area to the app to add
another function. I copied the text area exactly and I receive the following
message when I his submit on the lower box:

Bad Request The browser (or proxy) sent a request that this server could not
understand.

Here is the code all that was changed from the original app is adding a second
text area identical to the first. It appears ok but the problem arrises when I
hit submit even if the text area name is changed. I don't understand how the
server sees a difference between the 2nd and first box at this point. Heres
[the app that's being changed.](http://ven-diagram.herokuapp.com/) Its about
as sophisticated as you would expect given this question. Thx!

    
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ven Diagram</title>
    <style type=”text/css”>
    #pagearea {
    width: 100%;
    margin: 0 auto;
    }
    textarea {
    width: 48%;
    padding: 0 0 0 0;
    margin: 0 0 0 0;
    }
    input {
    width: 80px;
    height: 40px;
    }
     </style>
    </head>
    <body>
        <div id="pagearea">
        <h1>
        This program allows you to match text. The text must be unicode.
        Enter two text blocks to compare:
        </h1>
        <form action="/" method="post">
          <textarea name="A" cols="100" rows="20"></textarea>
          <textarea name="B" cols="100" rows="20"></textarea>
          <br />
          <input type="submit" value="Execute" />
        </form>
        </div>
    
     <div id="pagearea">
        <h1>
        This will give add and subtract permutations for numbers. 
        </h1>
        <form action="/" method="post">
          <textarea name="A" cols="100" rows="20"></textarea>
          <br />
          <input type="submit" value="Execute" />
        </form>
        </div>
    
        {% with messages = get_flashed_messages() %}
            {% if messages %}
                Results:
                <pre>
                    {% for message in messages %}
    {{ message }}
                    {% endfor %}
                </pre>
            {% endif %}
        {% endwith %}
    </body>
    </html>
    

Here is the Python code:

    
    
    #!flask/bin/python
    import flask, flask.views
    import os
    import urllib
    
    app = flask.Flask(__name__)
    app.secret_key = "REDACTED"
    
    class View(flask.views.MethodView):
        def get(self):
            return flask.render_template('index.html')
    
        def post(self):
            A = flask.request.form['A']
            B = flask.request.form['B']
            A = urllib.unquote(unicode(A))
            B = urllib.unquote(unicode(B))
            C = A.split()
            D = B.split()
            Both = []
            for x in C:
                if x in D:
                    Both.append(x)
            for x in range(len(Both)):
                Both[x]=str(Both[x])
            Final = []
            for x in set(Both):
                Final.append(x)
            MissingA = []
            for x in C:
                if x not in Final and x not in MissingA:
                    MissingA.append(x)
            for x in range(len(MissingA)):
                MissingA[x]=str(MissingA[x])
            MissingB = []
            for x in D:
                if x not in Final and x not in MissingB:
                    MissingB.append(x)
            for x in range(len(MissingB)):
                MissingB[x]=str(MissingB[x])
            #flask.flash("A:")
            #flask.flash(A)
            #flask.flash("B:")
            #flask.flash(B)
            #flask.flash("C:")
            #flask.flash(C)
            #flask.flash("D:")
            #flask.flash(D)
            flask.flash("Words in Both:")
            flask.flash(Final)
            flask.flash("Words in First Box Only:")
            flask.flash(MissingA)
            flask.flash("Words in Second Box Only:")
            flask.flash(MissingB)
            return self.get()
    
    app.add_url_rule('/', view_func=View.as_view('main'), methods=['GET', 'POST'])
    
    app.debug = True
    if __name__ == "__main__":
        # Bind to PORT if defined, otherwise default to 5000.
        port = int(os.environ.get('PORT', 5000))
        app.run(host='0.0.0.0', port=port)
    


Answer: even if you might think it's overkill. I learned that I want to use flask
extensions in every possible way there is.

In your case i would recommend
[wtforms](http://wtforms.readthedocs.org/en/latest/) with [flask-
wtf](https://flask-wtf.readthedocs.org/en/latest/) to better handle any sort
of forms.

