[英]Separation of Django view and template
For example, I have 2 pages listing news, one for desktop, one for mobile, the urls are 'news/list' and 'news/mobile/list'. 例如,我有2页列出新闻,一页用于桌面,一页用于移动,URL为“新闻/列表”和“新闻/移动/列表”。 Assume the logic of getting news from model is same. 假设从模型获取新闻的逻辑是相同的。
Currently, I work in this way. 目前,我以这种方式工作。
def mobile_list(request):
complexLogic()
return render(request, 'app/mobile/list.html', context)
def list(request):
complexLogic()
return render(request, 'app/list.html', context)
I am thinking how to do something like the following. 我正在考虑如何执行以下操作。 Is it currently supported in Django? Django当前支持它吗?
views.py views.py
def list(request):
complexLogic()
return request,'success',context
urls.py: urls.py:
('news/list', 'app.views.list', {'success' : 'app/list.html'}),
('news/mobile/list', 'app.views.list', {'success' : 'app/mobile/list.html'})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.