refractor from flask template
This commit is contained in:
parent
184eb978b7
commit
9b91c5cf73
13
Dockerfile
13
Dockerfile
@ -1,7 +1,12 @@
|
||||
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
|
||||
WORKDIR /code
|
||||
|
||||
COPY requirements.txt /code/requirements.txt
|
||||
COPY scripts /code/scripts
|
||||
RUN ls && ./scripts/setup-env.sh
|
||||
|
||||
ADD app app
|
||||
EXPOSE 8000
|
||||
CMD ["/code/venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0"]
|
@ -1,3 +1,6 @@
|
||||
from flask import Flask
|
||||
import os
|
||||
from fastapi import FastAPI
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
app = Flask(__name__)
|
||||
app = FastAPI()
|
||||
jinja = Jinja2Templates(os.path.join(os.path.dirname(__file__), "templates"))
|
||||
|
@ -1,3 +1 @@
|
||||
import flask
|
||||
|
||||
from . import simple_views
|
||||
|
@ -1,15 +1,14 @@
|
||||
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"))
|
||||
from fastapi import Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from app.app import app, jinja
|
||||
|
||||
|
||||
@simple_views.get("/")
|
||||
def index_page():
|
||||
return render_template("index.html", now=datetime.now())
|
||||
|
||||
|
||||
app.register_blueprint(simple_views)
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def index_page(request: Request):
|
||||
return jinja.TemplateResponse("index.html", context=dict(request=request, now=datetime.now()))
|
||||
|
@ -1,2 +1,6 @@
|
||||
Flask<3
|
||||
waitress
|
||||
fastapi
|
||||
jinja2
|
||||
ujson
|
||||
aiohttp
|
||||
databases
|
||||
uvicorn[standard]
|
@ -10,7 +10,7 @@ if [ ! -z "${PYPI_MIRROR}" ]; then
|
||||
fi
|
||||
|
||||
create-venv() {
|
||||
python -m venv venv
|
||||
python3 -m venv venv
|
||||
}
|
||||
|
||||
install-requirements() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user