Home  >  Article  >  Backend Development  >  Why does django need request when outputting Hello World?

Why does django need request when outputting Hello World?

WBOY
WBOYOriginal
2016-09-08 08:44:08991browse

Why when we use lamp environment, when accessing the php page, we need to return Hello World, just write echo 'Hello World' directly in the file, but django requires

<code>from django.http import HttpResponse

def index(request):
    return HttpResponse('Hello World')
~                                         </code>

What about this?

Reply content:

Why when we use lamp environment, when accessing the php page, we need to return Hello World, just write echo 'Hello World' directly in the file, but django requires

<code>from django.http import HttpResponse

def index(request):
    return HttpResponse('Hello World')
~                                         </code>

What about this?

It’s just an encapsulation of the http protocol.
PHP also has a similar library, just because PHP is not a strictly object-oriented language, of course it also supports object-oriented programming.
The advantage of this way of writing is that it has all the benefits of object-oriented. Better readability.

<code class="php">Response('hello!world')->withHeader(['Content-type:text/html;charset=utf8;']);
//PHP也可以以这样的方式编程.

//当然你也可以这样
header('Content-type:text/html;charset=utf8;');
echo 'hello!world';</code>

So this is just a programming method, no need to worry about it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn