#!/bin/bash# Inform the user about the script purposeecho"This script will set up a Flask project."# Ask for project directory nameread-p"Enter the name of your Flask project: " project_name
# Inform the user about creating the project directoryecho"Creating project directory: $project_name"# Create project directorymkdir"$project_name"cd"$project_name"# Inform the user about setting up the virtual environmentecho"Setting up virtual environment..."# Set up virtual environment
python -m venv venv
# Inform the user about activating the virtual environmentecho"Activating virtual environment..."# Activate virtual environmentsource venv/Scripts/activate
# Inform the user about installing Flaskecho"Installing Flask..."# Install Flask
pip install Flask
# Inform the user about creating app.pyecho"Creating app.py..."# Create app.pycat<<EOF > app.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
EOF
# Inform the user about creating templates directoryecho"Creating templates directory..."# Create templates directorymkdir templates
# Inform the user about creating index.html templateecho"Creating index.html template..."# Create index.html templatecat<<EOF > templates/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flask App</title>
</head>
<body>
<h1>Hello, Flask!</h1>
</body>
</html>
EOF
# Inform the user that setup is completeecho"Setup completed successfully!"# Open the project in Visual Studio Codeecho"Opening the project in Visual Studio Code..."
code .# Run the Flask appecho"Running the Flask app..."
python app.py
Command to run the script
bash flask_starter.sh
Now go to browser to see the app
http://localhost:5000/
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)