小编Bij*_*ham的帖子

Fastapi:jinja2.exceptions.TemplateNotFound:index.html

我正在尝试使用下面的代码使用 fastapi 重定向到登录页面。我使用 TemplateResponse 重定向到我已经在 templates 文件夹中创建的 index.html 页面。

文件结构如下

- main.py
- templates -> index.html
- static
Run Code Online (Sandbox Code Playgroud)

主要.py

from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles

app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")

templates = Jinja2Templates(directory="templates")


@app.get("/", response_class=HTMLResponse)
async def login_page(request :Request):
    return templates.TemplateResponse("index.html", {"request":request})
Run Code Online (Sandbox Code Playgroud)

我尝试这样做,但出现错误"jinja2.exceptions.TemplateNotFound: index.html",当我静态插入一些 HTML 代码时,它可以工作,但 TemplateResponse 无法正常工作。即使当我尝试在模板文件夹内提供 HTML 文件的完整路径时,它也会给出不同的错误。

请指导我如何使此代码工作,因为我尝试了不同的方法,但无论如何,此代码都会给出错误index.html template not found

python templates python-3.x fastapi

9
推荐指数
2
解决办法
5614
查看次数

找不到模块:无法解析“fs” - NextJS

我正在尝试将 Node-jsEncrypt 与 NextJS (tsx) 一起使用:

索引.tsx

import JSEncrypt from 'node-jsencrypt';
Run Code Online (Sandbox Code Playgroud)

包.json

"node-jsencrypt": "^1.0.0"
Run Code Online (Sandbox Code Playgroud)

日志

错误 - ./node_modules/node-jsencrypt/index.js:2:0

找不到模块:无法解析“fs”

注意:我没有找到该'webpack.config.js'文件,正如我在某些主题中看到的那样。

reactjs webpack next.js

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

fastapi ×1

next.js ×1

python ×1

python-3.x ×1

reactjs ×1

templates ×1

webpack ×1