Thursday, February 27, 2014

Re: Using Django without templates?

On Wednesday, February 26, 2014 6:16:39 PM UTC-4:30, ApathyBear wrote:
He mentioned something that I hadn't really gotten a chance to ask him more about
He told me to be careful with django templates because in terms of scale, they can cause problems and almost always need to be re-written. Rather he mentioned something like using a 'full stack'.
I think back, and I don't exactly follow what he means by that. Is their a way to use Django without templates? Is it better ? Why or why not?
Hello,

A web application is based on the HTTP protocol, that is text based. The purpose of the protocol is that a web browser request a document, and the server responds with a document text (may be other kind of content types, like images). Django manages this protocol through the use of views and url configurations: each url is managed by a view. The view responsibility is to deliver a (text) document, and do so via a django.http.response.HttpResponse object. So you only need to return, in your views, HttpResponse objects.

You can simply return in every view something like this:
return HttpResponse('hello world')

and it will work, without using templates. This is faster than loading a template with the text 'hello world', render and pass it to the view.

You can do that to return complex HTML (or other types of) documents of your site. Or you can use a template system and manage the HTML more easily with a bit more processing overhead. You can use other template systems besides the provided by Django, like Jinja (that has shown to be faster in some benchmarks compared to Django's).

Regards,
Camilo

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4f03f506-202a-4fce-92d4-e3dceb832ffa%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment