扫码关注官方订阅号
闭关修行中......
我的理解是你想根据不同的请求类型渲染不同的模板么?可以复现 get_template_names 方法:
class IndexView(BaseView, ListView): context_object_name = 'article_list' paginate_by = settings.PAGE_NUM # 分页--每页的数目 def get_template_names(self): ismobile = 从请求 self.request 中获得值 template_names = super().get_template_names() if ismobile: template_name = "m/index.html" else: template_name = 'index.html' template_names.insert(0, template_name ) return template_names
这个方法来自 TemplateResponseMixin,用于获取 django 视图渲染的模板,建议看一下 ListView 的源代码就清楚了。
TemplateResponseMixin
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
我的理解是你想根据不同的请求类型渲染不同的模板么?可以复现 get_template_names 方法:
这个方法来自
TemplateResponseMixin,用于获取 django 视图渲染的模板,建议看一下 ListView 的源代码就清楚了。