Python Flask : Starter Automated Template

When starting new project again, Some common structure needed to be written again and again. So I wrote a program nearly three years (2021) ago to Get Everything ready on one script. Here is the python script that makes everything ready

Here is is the revised version of the code

The Program Automatically generates basic scripts and files and necessary folder.

Copy, run the script And adjust the script on your necessary.


import os

x = os.getcwd()

os.mkdir("templates")
os.mkdir(os.path.join(x, "templates", "layouts"))
os.mkdir("static")
os.mkdir(os.path.join(x, "static", "css"))
os.mkdir(os.path.join(x, "static", "js"))
os.mkdir(os.path.join(x, "static", "img"))

app_w = """from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def home():
	title = "Home"
	return render_template('index.html', title=title)
"""

with open("app.py", "w+") as f:
	f.write(app_w)

css = """
body {
	background-color: #ccebff;
}
a, h1, h2, p {
	color: #3377ba8;
}
"""

with open(os.path.join(x, "static", "css", "main.css"), "w+") as f:
	f.write(css)

main = """<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ title }}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
{% block content %}
{% endblock %}
<footer>
<ul>
	<li> <a href="/">Home</a></li>
</ul>
&copy; 2021 Mahid
</footer>
</body>
</html>
"""

with open(os.path.join(x, "templates", "layouts", "main.html"), "w+") as f:
	f.write(main)

index = """{% extends "layouts/main.html" %}
{% block content %}
<h1>{{ title }}</h1>
<p>Hello world</p>
{% endblock %}
"""

with open(os.path.join(x, "templates", "index.html"), "w+") as f:
	f.write(index)