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