About this deal
Flask is a popular Python web framework, meaning it is a third-party Python library used for developing web applications. What Will You Find Here? Chemical Tools Watercolor Print Chemistry Lab Glassware Equipment Poster Laboratory Tubes Flasks Syringes Pipettes Science Art print If you have any problems, you can search for answers or ask a question on the Python extension Discussions Q&A. Next steps
app . route ( "/me" ) def me_api (): user = get_current_user () return { "username" : user . username , "theme" : user . theme , "image" : url_for ( "user_image" , filename = user . image ), } @app . route ( "/users" ) def users_api (): users = get_all_users () return [ user . to_json () for user in users ]
Run the app, navigate to a /hello/name URL, and observe that the message renders in blue. Stop the app when you're done.
Move the static and templates folders into hello_app, because these folders certainly contain app code. The following sections describe additional steps that you might find helpful in your work with Python and Visual Studio Code. Create a requirements.txt file for the environmentStart the debugger by selecting the Run> Start Debugging menu command, or selecting the green Start Debugging arrow next to the list ( F5): In the example above, when the app is running and accessed at http://domainname/, a user will receive "Hello, World!" as a response. Connecting the database in Flask In this new version of the index() function, you first open a database connection using the get_db_connection() function you defined earlier. Then you execute an SQL query to select all entries from the posts table. You implement the fetchall() method to fetch all the rows of the query result, this will return a list of the posts you inserted into the database in the previous step.