initial commit

This commit is contained in:
guochao 2022-08-28 13:02:29 +08:00
commit 184eb978b7
Signed by: guochao
GPG Key ID: 79F7306D2AA32FC3
12 changed files with 84 additions and 0 deletions

1
.dockerignore Symbolic link
View File

@ -0,0 +1 @@
.gitignore

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
venv
__pycache__
.idea
.vscode

7
Dockerfile Normal file
View File

@ -0,0 +1,7 @@
FROM python:3.10
ARG PYPI_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
ENV PYPI_MIRROR=${PYPI_MIRROR}
ADD . /app
WORKDIR /app
RUN ./scripts/setup-env.sh
CMD /app/venv/bin/waitress-serve app:app

5
app/__init__.py Normal file
View File

@ -0,0 +1,5 @@
from .app import app
from . import views
__all__ = ["app"]

3
app/app.py Normal file
View File

@ -0,0 +1,3 @@
from flask import Flask
app = Flask(__name__)

13
app/templates/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>A Sample Python Flask Project</title>
</head>
<body>
<div>A Sample Python Flask Project</div>
<div>{{now}}</div>
</body>
</html>

3
app/views/__init__.py Normal file
View File

@ -0,0 +1,3 @@
import flask
from . import simple_views

15
app/views/simple_views.py Normal file
View File

@ -0,0 +1,15 @@
from datetime import datetime
import os
from ..app import app
from flask import Blueprint, render_template
simple_views = Blueprint("views", __name__, template_folder=os.path.join(
os.path.dirname(__file__), "templates"))
@simple_views.get("/")
def index_page():
return render_template("index.html", now=datetime.now())
app.register_blueprint(simple_views)

2
requirements-dev.txt Normal file
View File

@ -0,0 +1,2 @@
autopep8
black

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
Flask<3
waitress

23
scripts/setup-env.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
SCRIPTDIR=$(dirname $0)
BASEDIR=$(dirname $SCRIPTDIR)
pip_options=()
if [ ! -z "${PYPI_MIRROR}" ]; then
pip_options+=(-i "${PYPI_MIRROR}")
fi
create-venv() {
python -m venv venv
}
install-requirements() {
pip install "${pip_options[@]}" -r requirements.txt
}
pushd ${BASEDIR}
create-venv
. ./venv/bin/activate
install-requirements

5
setup.py Normal file
View File

@ -0,0 +1,5 @@
from setuptools import setup
setup(
"python-templates"
)