Answer the question
In order to leave comments, you need to log in
Is it possible to specify template_name in urls.py?
I have two identical functions in views that output different templates. I want to use one function, but be able to output different templates.
def beats_by_user(request):
u = User.objects.get(username=request.user)
pk_list = u.profile.beats_order
pk_list = ast.literal_eval(pk_list)
objects = Post.objects.filter(user_beat_id__in=pk_list, author=u)
objects = dict([(obj.user_beat_id, obj) for obj in objects])
beats = [objects[user_beat_id] for user_beat_id in pk_list]
return render(request, 'blog/beat_list.html', {'beats': beats})
def user_profile(request):
u = User.objects.get(username=request.user)
pk_list = u.profile.beats_order
pk_list = ast.literal_eval(pk_list)
objects = Post.objects.filter(user_beat_id__in=pk_list, author=u)
objects = dict([(obj.user_beat_id, obj) for obj in objects])
beats = [objects[user_beat_id] for user_beat_id in pk_list]
return render(request, 'blog/user_main_profile.html', {'beats': beats})
url(r'^change-order/$', views.beats_by_user, name='beats'),
url(r'^my-profile/$', views.user_profile, name='beats'),
url(r'^change-order/$', views.user_profile, name='beats', template='тут имя шаблона'),
url(r'^my-profile/$', views.user_profile, name='beats', template='тут имя другого шаблона'),
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question