Home  >  Article  >  Backend Development  >  Detailed explanation of how Python displays back-end information on the front-end

Detailed explanation of how Python displays back-end information on the front-end

高洛峰
高洛峰Original
2017-03-10 19:08:092159browse

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",{&#39;xianshi&#39;: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!

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