Home > OS >  Flask object has no attribute get while following linode tutorial
Flask object has no attribute get while following linode tutorial

Time:11-23

Good morning,

Following the linode tutorial here to create a RESTful API https://www.linode.com/docs/guides/create-restful-api-using-python-and-flask/

I keep getting an attribute error 'Flask' object has no attribute 'get'

Not sure what's going on because I'm following the tutorial precisely.

from flask import Flask

application = Flask(__name__)

in_memory_datastore = {
   "COBOL" : {"name": "COBOL", "publication_year": 1960, "contribution": "record data"},
   "ALGOL" : {"name": "ALGOL", "publication_year": 1958, "contribution": "scoping and nested functions"},
   "APL" : {"name": "APL", "publication_year": 1962, "contribution": "array processing"},
}

@application.get('/programming_languages')
def list_programming_languages():
   return {"programming_languages":list(in_memory_datastore.values())}

CodePudding user response:

You're probably running an older version of Flask (v2.0.x or below).

Flask added @application.get feature in v2.1.x branch (check documentation here).

For older flask versions use @application.route('/programming_languages', methods=['GET']). Documentation here.

  • Related