我正在 Python 中的 Google App Engine 中的 webapp2 框架上构建一个应用程序。我一直使用 Jinja2 作为我的模板引擎和 Twitter Bootstrap 用于样式设置。在构建了一个不错的“layout.html”并让所有其他模板都继承自“layout.html”之后,我进行了部署。所有页面呈现属性,除了一个,它的 url 是动态的。
这是 WSGI 处理程序的样子:
webapp2.WSGIApplication = ([('/login', LoginPage),
('/updates', Update),
('/updates/.*', Individual)],
debug = True)
# as you can see I'm using the catchall regex for Individual
从功能上讲, Individual处理的每个动态生成的 url 都可以正常运行。这是处理程序,再次,此处理程序中的所有内容都将被执行。
class Individual(Handler):
def get(self):
url_u = str(self.request.url)
posit = url_u.find('updates')
bus1 = url_u[posit+8:]
bus = bus1.replace('%20', chr(32))
b = BusUpdates.all()
this_bus = b.order('-timestamp').filter('bus = ', bus).fetch(limit=10)
name = users.get_current_user()
user = None
if name:
user = name.nickname()
logout = users.create_logout_url(self.request.uri)
self.render("individual.html", bus=bus, user=user, this_bus=this_bus, logout=logout)
典型的 URL 如下所示: http ://www.megabusfinder.appspot.com/updates/St%20Louis,%20MO-Chicago,%20IL-4-12-930AM-310PM
这是我的 app.yaml 文件
application: megabusfinder
version: 1
runtime: python27
api_version: 1
threadsafe: no
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /static/stylesheets
static_dir: static/stylesheets
- url: /twitter-bootstrap-37d0a30
static_dir: twitter-bootstrap-37d0a30
- url: /static/xml
static_dir: static/xml
- url: .*
script: main.app
builtins:
- remote_api: on
libraries:
- name: webapp2
version: "2.5.1"
- name: jinja2
version: latest
现在,我以前有从我的“layout.html”继承的“individual.html”。大约一个小时前,我不再这样做了,我已经手动将我在“layout.html”中使用的所有必要引导程序添加到“individual.html”中。即使这样,也没有任何样式生效。
提前致谢。