我有2个模板,第一个是团队vs团队,最后一个是玩家vs。例如,client_budget
代表团队对团队。但是,心血结晶的比赛是玩家对玩家。我的网址路径Dota2
我想要这样:
'<str:gameslug>/turnuva/<str:tournamentslug>/mac/<str:lolslug>'
我该怎么办?
if gameslug==lol return render template1
if gameslug==heartstone return template2
答案 0 :(得分:2)
好吧,您基本上可以在渲染之前检查gameslug
变量中的内容。
def game_detail(request,tournamentslug,lolslug,gameslug):
game = get_object_or_404(
LeagueofLegendsGame,
tournament__tournament_slug=tournamentslug,
lol_slug=lolslug,
tournament__game__slug=gameslug
)
context={
'game':game,
}
if gameslug == 'lol':
template = 'template1.html'
elif gameslug == 'heartstone':
template = 'template2.html'
#else render the one you're already rendering
else:
template = 'esports/lolgame.html'
return render(request, template, context)