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

Why does django need request when outputting Hello World?

WBOY
Release: 2016-09-08 08:44:08
Original
1011 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template