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
|
FROM python:3.10
|
||||||
ARG PYPI_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
|
ARG PYPI_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
ENV PYPI_MIRROR=${PYPI_MIRROR}
|
ENV PYPI_MIRROR=${PYPI_MIRROR}
|
||||||
ADD . /app
|
WORKDIR /code
|
||||||
WORKDIR /app
|
|
||||||
RUN ./scripts/setup-env.sh
|
COPY requirements.txt /code/requirements.txt
|
||||||
CMD /app/venv/bin/waitress-serve app:app
|
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
|
from . import simple_views
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
from ..app import app
|
|
||||||
from flask import Blueprint, render_template
|
|
||||||
|
|
||||||
simple_views = Blueprint("views", __name__, template_folder=os.path.join(
|
from fastapi import Request
|
||||||
os.path.dirname(__file__), "templates"))
|
from fastapi.responses import HTMLResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
|
from app.app import app, jinja
|
||||||
|
|
||||||
|
|
||||||
@simple_views.get("/")
|
@app.get("/", response_class=HTMLResponse)
|
||||||
def index_page():
|
async def index_page(request: Request):
|
||||||
return render_template("index.html", now=datetime.now())
|
return jinja.TemplateResponse("index.html", context=dict(request=request, now=datetime.now()))
|
||||||
|
|
||||||
|
|
||||||
app.register_blueprint(simple_views)
|
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
Flask<3
|
fastapi
|
||||||
waitress
|
jinja2
|
||||||
|
ujson
|
||||||
|
aiohttp
|
||||||
|
databases
|
||||||
|
uvicorn[standard]
|
@ -10,7 +10,7 @@ if [ ! -z "${PYPI_MIRROR}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
create-venv() {
|
create-venv() {
|
||||||
python -m venv venv
|
python3 -m venv venv
|
||||||
}
|
}
|
||||||
|
|
||||||
install-requirements() {
|
install-requirements() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user