retrovius
retrovius

Reputation: 854

Flask TypeError: argument of type '_RequestGlobals' is not iterable

TL;DR

I'm working on this website: sendsomething.net

I'm getting the following error in my Flask project:

Traceback (most recent call last):
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask/app.py", line 1518, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask/app.py", line 1506, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask/app.py", line 1504, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask/app.py", line 1264, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask/app.py", line 1262, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask/app.py", line 1248, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/leilers/sendsomething/sendsomething_flask/sendsomething/views.py", line 62, in hello
    return render_template('hello.html')
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask/templating.py", line 121, in render_template
    ctx.app.update_template_context(context)
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask/app.py", line 661, in update_template_context
    context.update(func())
  File "/home/leilers/sendsomething/sendsomething_flask/sendsomething/views.py", line 54, in inject_login_form
    g.login_form = LoginForm()
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/wtforms/form.py", line 208, in __call__
    return type.__call__(cls, *args, **kwargs)
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask_wtf/form.py", line 87, in __init__
    super(FlaskForm, self).__init__(formdata=formdata, **kwargs)
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/wtforms/form.py", line 274, in __init__
    self.process(formdata, obj, data=data, **kwargs)
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/wtforms/form.py", line 131, in process
    field.process(formdata)
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/wtforms/csrf/core.py", line 43, in process
    self.current_token = self.csrf_impl.generate_csrf_token(self)
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask_wtf/csrf.py", line 134, in generate_csrf_token
    token_key=self.meta.csrf_field_name
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/flask_wtf/csrf.py", line 42, in generate_csrf
    if field_name not in g:
  File "/home/leilers/sendsomething/env/lib/python2.7/site-packages/werkzeug/local.py", line 365, in <lambda>
    __contains__ = lambda x, i: i in x._get_current_object()
TypeError: argument of type '_RequestGlobals' is not iterable

More in-depth

I have no experience it web design, so I'm stumped (and have been for days). If the above is all you need to see to help me solve my issue, then that's awesome. In case you need more detail, here it is:

The relavent section of my Flask project's <root>/sendsomething/views.py

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

The file <root>/sendsomething/templates/index.html does exist. It's contents are not important, as changing the contents does not have an effect on the error. You can actually see the output by visiting sendsomething.net.

I have read and attempted the solution to this related issue, Flask argument of type '_RequestGlobals' is not iterable, which appears to be the only other instance of someone experiencing this issue.

I am in my virtualenv, running python 2.7.16. I have run pip install Werkzeug --update (although my requirements.txt specifies that it should use Werkzeug 0.8.2). I've ensured that which python points to the right place.

If you need any more information, please let me know. Thank you for your assistance!

Upvotes: 0

Views: 319

Answers (1)

Katie
Katie

Reputation: 341

This just just my first glance at it, so I apologize if it isn't a helpful response. It appears your code looks like this:

59  @app.route("/")
60  def hello():
61      #return render_template('index.html')
62      return render_template('hello.html')

And you said index.html exists... It looks like the return for index.html is commented out and it still tries to go to hello.html.

So it should be the following, as you described in your question:

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

Upvotes: 1

Related Questions