我刚刚开始使用webapp2框架和jinja2模板在python中使用谷歌应用程序引擎。我似乎无法启动和运行我的第一个非常简单的脚本。我所需要的就是让脚本提供index.html文件(位于同一目录中)。
下面是app.yaml文件:
libraries
- name: webapp2
version: latest
- name: jinja2
version: latest
application: practice
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: practice.application下面是practice.py:
import os
import webapp2
from jinja2 import Enviroment, FileSystemLoader
loader = jinja2.FileSystemLoader(os.path.dirname(__FILE__)
env = jinja2.Enviroment(loader)
class MainPage(webapp2.RequestHandler):
def get(self):
template = env.get_template('index.html')
self.response.write(template.render())
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)更新:我正在从Google应用程序引擎启动器本地运行此程序。当我尝试打开该文件时,我收到一个服务器错误,其中包含以下描述
The website encountered an error while retrieving http://localhost:9080/. It may be
down for maintenance or configured incorrectly."发布于 2013-06-14 15:34:36
下面是你的代码不能运行的原因:
你的__FILE__ is malformed
<>F217
下面是我认为你的代码应该是什么样子:
app.yaml
application: practice
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
handlers:
- url: /.*
script: practice.applicationpractice.py
import jinja2
import os
import webapp2
loader = jinja2.FileSystemLoader(os.path.dirname(__file__))
env = jinja2.Environment(loader=loader)
class MainPage(webapp2.RequestHandler):
def get(self):
template = env.get_template('index.html')
self.response.write(template.render())
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)我建议你做以下事情,让你的生活变得更容易:
下载eclipse (我假设您还没有给出语法错误) http://eclipse.org/
希望这篇文章能帮你上路。
快乐编码:)
发布于 2013-08-29 16:43:56
在webapp2中,您应该使用应用程序而不是应用程序,因此最后一行应该如下所示:
app = webapp2.WSGIApplication([('/', MainPage),], debug=True)https://stackoverflow.com/questions/17101744
复制相似问题