[Answer]-Django: can "double" 'render_to_response' be unified into only one view?

1👍

Yes, you can use the single view. Add the default None value for the id (or pk) argument:

def show_elementi(request, pk=None):
    elementimenu = ElementiTab.objects.all()
    detail = get_object_or_404(ElementiTab, pk=pk) if pk else None
    return render(request, 'homepage/prova.html',
                  {'elementimenu': elementimenu, 'detail': detail})

And then map both urls to this view:

url(r'^homepage/prova/$', views.show_elementi),
url(r'^show_detail/(?P<pk>\d+)/$', views.show_elementi),

Leave a comment