To create a basic Flask server, you can follow these steps:
Install Flask by running pip install Flask
in your terminal.
Create a new Python file and import Flask:
main.py47 chars3 lines
Use routes to define the behavior of the server, for example:
main.py55 chars4 lines
Run the application using:
main.py41 chars3 lines
This tells Python to run the application only if the code is executed directly rather than imported as a module.
Finally, run your Python file from the terminal using:
main.py43 chars3 lines
This will start the server, and you should be able to see your "Hello World!" message by visiting http://127.0.0.1:5000/ in your web browser.
This is just a simple example, but Flask can be extended to create more complex web applications and API endpoints.
gistlibby LogSnag