Render arasındaki fark nedir Django - (), render_to_response() ve direct_to_template()?
render()
, render_to_response()
direct_to_template()
arasında bir görünümde ne fark eder (dilde python/django bir çaylak anlayabilir)?
Nathan Borror's basic apps examples ör
def comment_edit(request, object_id, template_name='comments/edit.html'):
comment = get_object_or_404(Comment, pk=object_id, user=request.user)
# ...
return render(request, template_name, {
'form': form,
'comment': comment,
})
Ama aynı zamanda gördüm
return render_to_response(template_name, my_data_dictionary,
context_instance=RequestContext(request))
Ve
return direct_to_template(request, template_name, my_data_dictionary)
Farkı, ne herhangi bir durumda kullanmak için ne?
CEVAP
https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render
render(request, template[, dictionary][, context_instance][, content_type][, status][, current_app])
render()
otomatik olarak kesinlikle bundan sonra kullanmayacak RequestContext
kullanacağı 1.3 render_to_response
için kutusundan yeni çıkmış bir kısayoldur.
https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render-to-response
render_to_response(template[, dictionary][, context_instance][, mimetype])¶
render_to_response
standart oluşturma fonksiyonu ve bu tür eğitimler kullanılır. RequestContext
context_instance=RequestContext(request)
belirtmek gerek
direct_to_template
genel bakış bu kullanım görüşlerimi (karşıt olarak benim URL) çünkü yeni render()
fonksiyonu otomatik olarak kullanır RequestContext
ve context_processor
ler.
Ama direct_to_template
kaçınılmalıdırson olarak da genel görüş kabul edilmez işlevi. Ya render
ya da gerçek bir sınıf https://docs.djangoproject.com/en/1.3/topics/generic-views-migration/ bkz
Uzun, uzun zaman içinde RequestContext
yazılan almadım mutluyum.
Django statik dosyalar ve medya dosyal...
Bir URI, URL ve URN arasındaki fark ne...
Aramak ve uygulamak arasındaki fark ne...
@Staticmethod ve @Python classmethod a...
Match_parent ve fill_parent arasındaki...