This repository contains a Python script that sets up a Flask environment with a predefined directory structure and essential files. The script automates the creation of directories, necessary files, and a virtual environment named myEnv
.
The script creates the following directory structure:
project_root/ │ ├── app.py ├── requirements.txt ├── .gitignore ├── templates/ │ ├── index.html │ └── base.html └── static/ ├── js/ ├── css/ │ ├── index.css │ └── base.css └── img/
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)
### `templates/index.html`
```html
{% extends 'base.html' %}
{% block content %}
<h1>Welcome to Flask!</h1>
{% endblock %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}My Website{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<div class="container">
{% block content %}{% endblock %}
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
color: #333;
}
h1 {
color: #007bff;
}
body {
margin: 0;
padding: 0;
box-sizing: border-box;
}
Flask
myEnv/
__pycache__/
*.pyc
instance/
.webassets-cache
-
Clone the repository:
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name
-
Run the setup script:
python setup_flask_env.py
-
Activate the virtual environment:
- On Windows:
myEnv\Scripts\activate
- On macOS and Linux:
source myEnv/bin/activate
- On Windows:
-
Run the Flask application:
python app.py
-
Open your browser and go to
http://127.0.0.1:5000
to see the Flask application in action.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any changes or improvements.
For any questions or inquiries, please contact [Your Name] at [your-email@example.com].
Make sure to replace placeholders like `yourusername`, `your-repo-name`, `Your Name`, and `your-email@example.com` with your actual GitHub username, repository name, name, and email address, respectively. This `README.md` file provides a comprehensive guide for users to understand and use the Flask environment setup script.