Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Flask or Quart NameError: global name 'g' is not defined

I got a problem when I tried to test a flask app that I can not access the g variable.

The api which is gonna tested looks like this:

user = query_object.get(g.user_id)   # here the exception raises

When I run the test, it raises:

NameError: global name 'g' is not defined
like image 759
streethacker Avatar asked Mar 26 '15 06:03

streethacker


1 Answers

What are your imports? You should try and add

from flask import g

Or, if you're using Quart

from quart import g
like image 192
Vladimir T. Avatar answered Oct 14 '22 15:10

Vladimir T.