There are several ways to create web applications in Python. Two popular frameworks are Flask and Django.
Flask:
Flask is a lightweight web framework that is easy to learn and use. To create a simple web app using Flask, follow these steps:
Install Flask using pip:
main.py18 chars2 lines
Create a new Python file and import the Flask module:
main.py46 chars3 lines
Define the routes of your web app using the @app.route decorator:
main.py55 chars4 lines
Run the app using the app.run method:
main.py41 chars3 lines
Navigate to http://localhost:5000/ in your web browser to see the "Hello, World!" message.
Django
Django is a more robust web framework that provides many features out of the box. To create a simple web app using Django, follow these steps:
Install Django using pip:
main.py19 chars2 lines
Create a new Django project:
main.py38 chars2 lines
Create a new Django app:
main.py34 chars2 lines
Define the views of your web app in the app's views.py file:
main.py98 chars5 lines
Define the URL patterns for your web app in the app's urls.py file:
main.py107 chars7 lines
Run the app using the Django development server:
main.py27 chars2 lines
Navigate to http://localhost:8000/ in your web browser to see the "Hello, World!" message.
gistlibby LogSnag