1

I'm working on a mathematical app that takes some inputs from the users and outputs a table of a mathematical relationship using flask and this error occurs : jinja2.exceptions.UndefinedError: 'zip' is undefined

File "C:\Python37\Scripts\venv\lib\site-packages\flask\app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python37\Scripts\venv\lib\site-packages\flask\app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "C:\Python37\Scripts\venv\lib\site-packages\flask\app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python37\Scripts\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Python37\Scripts\venv\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python37\Scripts\venv\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python37\Scripts\venv\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python37\Scripts\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Python37\Scripts\venv\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python37\Scripts\venv\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\A.Toba\Desktop\Flask\simple\main.py", line 6, in index
return render_template('index.html')
File "C:\Python37\Scripts\venv\lib\site-packages\flask\templating.py", line 135, in render_template
context, ctx.app)
File "C:\Python37\Scripts\venv\lib\site-packages\flask\templating.py", line 117, in _render
rv = template.render(context)
File "C:\Python37\Scripts\venv\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "C:\Python37\Scripts\venv\lib\site-packages\jinja2\environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "C:\Python37\Scripts\venv\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python37\Scripts\venv\lib\site-packages\jinja2\_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "C:\Users\A.Toba\Desktop\Flask\simple\templates\index.html", line 55, in top-level template code
{% for i, j in zip(pwf_table,q_table) %}

main.py

in this file I was trying to take user inputs from the template form and put their values into variables and apply some python code on these values and send back the result to be published in a table in the same page.

from flask import Flask, render_template, request
app = Flask(__name__)

@app.route('/')
def index():
   return render_template('index.html')

@app.route('/',methods = ['POST', 'GET'])
def result():
   if request.method == 'POST':
      Pr = request.form["pr"]
      Q = request.form["tq"]
      PWF = request.form["tpwf"]
      step = request.form["step"]
      pwf = list(range(0,Pr))
      q = []
      qmax = Q / (1 - 0.2*PWF/Pr - .8*(PWF/Pr)**2 )
      [q.append(qmax * (1 - 0.2*i/Pr - .8*(i/Pr)**2 )) for i in pwf ]
      pwf_table = pwf[::step]
      q_table = q[::step]
      return render_template("index.html",result = result)

if __name__ == '__main__':
   app.run(debug = True)

in this bootstrap template I was trying to request data from user form to flask and sent the output to a table in the same page that is generated by submitting the form

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="\static\css" rel="stylesheet">


    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <h1>Hello, world!</h1>
    <form action="http://localhost:5000" method="POST">
      <div class="form-group">
        <label for="">Pr:</label>
        <input type="text" class="form-control" name="pr" id="pwd">
      </div>
      <div class="form-group">
        <label for="pwd">Test Q:</label>
        <input type="text" class="form-control" name="tq" id="pwd">
      </div>
      <div class="form-group">
        <label for="pwd">Test PWF:</label>
        <input type="text" class="form-control" name="tpwf" id="pwd">
      </div>
      <div class="form-group">
        <label for="pwd">Table step:</label>
        <input type="text" class="form-control" name="step" id="pwd">
      </div>
      <button type="submit" class="btn btn-default">Submit</button>
   </form>


   <div class="container">
  <h2>Striped Rows</h2>
  <p>The .table-striped class adds zebra-stripes to a table:</p>
  <table class="table table-striped">
    <thead>
      <tr>
        <th>PWF</th>
        <th>Q</th>
      </tr>
    </thead>
    <tbody>
      {% for i, j in zip(pwf_table,q_table) %}
        <tr>
          <th>i</th>
          <th>j</th>
        </tr>
      {% endfor %}  
    </tbody>
  </table>
</div>

how to solve this error

Ahmed Toba
  • 37
  • 1
  • 8
  • If your question gets closed, that's no mark against you. Stackoverflow favors having a single answer to a given problem, and the automated ways of suggesting that your question might relate to other questions isn't perfect. Hopefully you've gotten your question answered. Welcome to stackoverflow. – Dave W. Smith Nov 24 '18 at 03:52
  • the error has been solved and another error occured with ......TypeError: 'generator' object is not subscriptable – Ahmed Toba Nov 24 '18 at 17:21
  • Reduce it down to a small example that demonstrates the problem, and post it as a new question. – Dave W. Smith Nov 24 '18 at 19:54

0 Answers0