/mk_flask_env

This creates my local starting environment for flask projects

MIT LicenseMIT

Flask Environment Setup Script

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.

Directory Structure

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/

File Contents

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)

### `templates/index.html`
```html
{% extends 'base.html' %}
{% block content %}
<h1>Welcome to Flask!</h1>
{% endblock %}

templates/base.html

<!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>

static/css/index.css

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    color: #333;
}
h1 {
    color: #007bff;
}

static/css/base.css

body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

requirements.txt

Flask

.gitignore

myEnv/
__pycache__/
*.pyc
instance/
.webassets-cache

Usage

  1. Clone the repository:

    git clone https://github.com/yourusername/your-repo-name.git
    cd your-repo-name
  2. Run the setup script:

    python setup_flask_env.py
  3. Activate the virtual environment:

    • On Windows:
      myEnv\Scripts\activate
    • On macOS and Linux:
      source myEnv/bin/activate
  4. Run the Flask application:

    python app.py
  5. Open your browser and go to http://127.0.0.1:5000 to see the Flask application in action.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes or improvements.

Contact

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.