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

高洛峰
Release: 2017-03-10 19:08:09
Original
2150 people have browsed it

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

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

In The code for looping the backend in the front-end html:

<html>
<body>
<h1>下面是后端返回的内容</h1>
 
{% for i in xianshi %}
{{ i }}
{% endfor %}
 
</body>
</html>
Copy after login

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

If the amount of code is too large, you can install django-debugtools

pip install django-debugtools
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!