gpt4 book ai didi

python - TemplateNotFound : templates/HomePage. 网站部署在 Google 应用引擎上时出现 html 错误,但网站在本地主机上运行时运行良好

转载 作者:行者123 更新时间:2023-11-28 22:24:45 26 4
gpt4 key购买 nike

我正在尝试部署我的个人网站,但是当我在本地主机上运行我的网站时遇到了一个大错误,一切运行正常。但是我已经通过 Google App 部署了我的网站,但它不起作用。我一直在 Here is a screenshot of the error I get 以下收到此错误

我不知道为什么要这样做,因为 Homepage.html 文件位于模板文件夹中。 This a screenshot of my file path and the Python code I wrote .这是我写的代码

import jinja2
import os
import webapp2
import logging
from google.appengine.api import users
from google.appengine.ext import ndb
import datetime
import json
import unicodedata
from google.appengine.api import users

# the two lines of code below makes the jinja work
jinja_environment = jinja2.Environment(loader=
jinja2.FileSystemLoader(os.path.dirname(__file__)))

class HomePage(webapp2.RequestHandler):
def get(self):
template =
jinja_environment.get_template('templates/HomePage.html')
self.response.write(template.render())

class AboutMe(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('templates/Aboutme.html')
self.response.write(template.render())

class Contact(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('templates/Contact.html')
self.response.write(template.render())


class Projects(webapp2.RequestHandler):
def get(self):
template =
jinja_environment.get_template('templates/Projects.html')
self.response.write(template.render())

app = webapp2.WSGIApplication([
('/', HomePage), #HomePage
('/AboutMe.html',AboutMe),
('/Contact.html',Contact),
('/Projects.html',Projects)

], debug=True)
}

这是我的 app.yaml 文件

application: israel-ali
version: 1
runtime: python27
api_version: 1
threadsafe: yes
# order matters always have this order
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico

- url: /resources
static_dir: static_folder

- url: .*
script: main.app

libraries:
- name: jinja2
version: latest
- name: webapp2
version: "2.5.2"

[在此处输入图片描述][3]

最佳答案

文件名在 GAE 上区分大小写。

您的代码寻找名为 HomePage.html 的模板,而(我怀疑是)实际模板名为 Homepage.htmlAboutme.htmlAboutMe.html 也有类似的问题。

您只需要在 .get_template() 中使用实际的文件名即可。

关于python - TemplateNotFound : templates/HomePage. 网站部署在 Google 应用引擎上时出现 html 错误,但网站在本地主机上运行时运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46098722/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com