title: NameError: name 'request' is not defined
body: <p>I got this Python Code, and somehow I get the Error Message: </p>
  
  <blockquote>
  <pre><code>File "/app/identidock.py", line 13, in mainpage
  if request.method == 'POST':
  NameError: name 'request' is not defined
  </code></pre>
  </blockquote>
  
  <p>But I really can't find my mistake. Can someone please help me with that? </p>
  
  <pre><code>from flask import Flask, Response
  import requests
  import hashlib
  
  app = Flask(__name__)
  salt = "UNIQUE_SALT"
  default_name = 'test'
  
  @app.route('/', methods=['GET', 'POST'])
  def mainpage():
  
      name = default_name
      if request.method == 'POST':
          name = request.form['name']
  
      salted_name = salt + name
      name_hash = hashlib.sha256(salted_name.encode()).hexdigest()
  
      header = '&lt;html&gt;&lt;head&gt;&lt;title&gt;Identidock&lt;/title&gt;&lt;/head&gt;&lt;body&gt;'
      body = '''&lt;form method="POST"&gt;
                Hallo &lt;input type="text" name="name" value="{0}"&gt;
                &lt;input type="submit" value="Abschicken"&gt;
                &lt;/form&gt;
                &lt;p&gt; Du siehst aus wie ein: &lt;/p&gt;
               &lt;img src="/monster/{1}"/&gt;
             '''.format(name, name_hash)
      footer = '&lt;/body&gt;&lt;/html&gt;'
  
      return header + body + footer
  
  @app.route('/monster/&lt;name&gt;')
  def get_identicon(name):
  
      r = requests.get('http://dnmonster:8080/monster/' \
          + name + '?size=80')
      image = r.content
  
      return Response(image, mimetype='image/png')
  
  if __name__ == '__main__':
      app.run(debug=True, host='0.0.0.0')
  </code></pre>