SORU
1 Mart 2011, Salı


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
1 Mart 2011, Salı


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


https://docs.djangoproject.com/en/1.8/ref/generic-views/#django-views-generic-simple-direct-to-template

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_processorler.

Ama direct_to_templatekaçı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.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Erica Griffin

    Erica Griffi

    8 HAZİRAN 2009
  • UrAvgConsumer

    UrAvgConsume

    1 Ocak 2012
  • Yanko Kral

    Yanko Kral

    8 HAZİRAN 2006