简体   繁体   English

动态direct_to_template

[英]Dynamic direct_to_template

In my webapp, there are a lot of errors or other messages that just show a template that is very close to the URL. 在我的Web应用程序中,有很多错误或其他消息,它们只是显示了一个非常接近URL的模板。 At the moment, I have half a dozen static mappers like this: 目前,我有六个这样的静态映射器:

(r'^/message/foo/$', 'direct_to_template', {'template': 'message/foo.html'}),
(r'^/message/bar/$', 'direct_to_template', {'template': 'message/bar.html'}),

Is there some built-in way I can hook up /message/*/ to show the template message/*.html ? 有什么内置的方法可以连接/message/*/以显示模板message/*.html吗?

This is pretty easy. 这很容易。 Do it like this: 像这样做:

(r'^/message/(?<name>\d+)/$', 'your_app.views.direct_to_template')

and: 和:

def direct_to_template(name):
  return render_to_response('message/%s.html' % name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM