2
我很困惑。事情昨天晚上效果很好,今天突然停止工作。GAE爲什麼找不到我的模板文件夾中的文件?
此頁面的目的是生成一個顏色列表。這些模板位於他們自己的名爲「模板」的文件夾中,但GAE似乎無法找到這些模板。
我在這裏做錯了什麼?
main2.py:
import bottle
from bottle import static_file
from google.appengine.ext.webapp import util
from bottle import route
# Load the template system
from jinja2 import Environment, FileSystemLoader
# Indicate from where the templates will be loaded
env = Environment(loader=FileSystemLoader('./templates/'))
# for randomly picking colors
import random
colors = 'green red blue';
@route('/favicon.ico')
def send_image():
filename = 'favicon.ico'
return static_file(filename, root='./images/', mimetype='image/ico');
@route('/hello')
def hello():
template = env.get_template('home.html');
color_list = colors.split();
num_colors = random.randint(0,len(color_list)+1);
color_list = color_list[:num_colors];
return template.render(title="Color List Page!", color_list=color_list);
util.run_wsgi_app(bottle.default_app())
的app.yaml
application: yao-webapp2
version: 1
api_version: 1
runtime: python
handlers:
- url: .*
script: main2.py
/templates/base.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
{% block title %}
I am stupid as heck: I forgot to fill in a title.
{% endblock %}
</title>
</head>
<body>
{% block content %}
No body knows the trouble I've seen.
{% endblock %}
</body>
</html>
/templates/home.html
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock %}
{% block content %}
<h1>Some Colors I know </h1>
<p>I have a list of colors that I know</p>
{% if color_list %}
<ul>
{% for color in color_list %}
<li> {{ color }} </li>
{% endfor %}
</ul>
{% else %}
<p>Oops! No colors.</p>
{% endif %}
{% endblock %}
以及唯一的錯誤GAE告訴我的是,其404 = /,我應該用別的東西代替__file__或讓它原樣?我試了一下,它仍然給我一個404 – iCodeLikeImDrunk 2012-03-11 18:55:32
它給你一個404 /你好? – aschmid00 2012-03-11 19:10:48
是的,當我只是去「:8080」它顯示「你好世界」,然後當我嘗試「本地主機:8080 /你好」它給了我404 ... – iCodeLikeImDrunk 2012-03-11 19:20:20