Home > Article > Backend Development > Detailed explanation of how Python displays back-end information on the front-end
This article explains in detail how python displays back-end information on the front-end
First, you need to add the following to test.html:
<html> <body> <h1>下面是后端返回的内容</h1> {{ xianshi }} </body> </html>
Back-end code:
import datetime from django.shortcuts import render_to_response def current(request): now=datetime.datetime.now() return render_to_response("test.html",{'xianshi':now})
In The code for looping the backend in the front-end html:
<html> <body> <h1>下面是后端返回的内容</h1> {% for i in xianshi %} {{ i }} {% endfor %} </body> </html>
plus the if statement:
<html> <body> <h1>下面是后端返回的内容</h1> {% for i in xianshi %} {% if "2" in i %} <p style="color:red">{{ i }}</p> {% else %} <p style="color:green">{{ i }}</p> {% endif %} {% endfor %} </body> </html>
If the amount of code is too large, you can install django-debugtools
pip install django-debugtools
for troubleshooting
The above is the detailed content of Detailed explanation of how Python displays back-end information on the front-end. For more information, please follow other related articles on the PHP Chinese website!