且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改基于用户代理的Django模板

更新时间:2023-11-26 20:22:16

而不是动态更改模板目录,您可以修改请求并添加一个值,让您的视图知道用户是否在iphone上。然后包装render_to_response(或任何您用于创建HttpResponse对象的东西),以获取iphone版本的模板,而不是标准的html版本,如果他们使用的是iphone。

Rather than changing the template directories dynamically you could modify the request and add a value that lets your view know if the user is on an iphone or not. Then wrap render_to_response (or whatever you are using for creating HttpResponse objects) to grab the iphone version of the template instead of the standard html version if they are using an iphone.