[Tutor] if request.method == 'GET': NameError: global name 'request' is not defined
Alan Gauld
alan.gauld at btinternet.com
Mon Jan 18 03:58:23 EST 2016
On 18/01/16 02:13, sudipto manna wrote:
> Here is the code snippet:
>
> File#FlaskTest2.py
>
> from flask import Flask
>
> app = Flask(__name__)
>
> #Make an app.route() decorator here
> @app.route("/puppies/", methods = ['GET' , 'POST'])
> def puppiesFunction():
> if request.method == 'GET':
> return getAllPuppies()
>
As suspected the error is correct. You do not have a request object
anywhere in your code. A quick Google tells me that it is part
of Flask. So you need to import request from your flask module:
from flask import Flask, request,,....# any other names you use
hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list