Home >Web Front-end >HTML Tutorial >Detailed explanation of the steps for django to display background table data in the front-end html page

Detailed explanation of the steps for django to display background table data in the front-end html page

高洛峰
高洛峰Original
2017-03-23 10:11:078866browse

I created a user table and entered some information into the table. So how to display the information in this table in the previous html page?

Detailed explanation of the steps for django to display background table data in the front-end html page

1. Add the URL in learn/urls.py

Detailed explanation of the steps for django to display background table data in the front-end html page

2. Define a method in views, To respond to the user's request

Detailed explanation of the steps for django to display background table data in the front-end html page

Here is a function user_list() defined to respond to the user's request to access http://127.0.0.1/learn/user

This method is to use html template files to render and display content.

def user_list(request):
    users = User.objects.all()  #将User表中的所有对象赋值给users这个变量,它是一个列表
    return render(request, 'home.html', {'users': users}) 生成一个user变量,这个变量可以给templates中的html文件使用

3. Edit the learn/templates/home.html file

Detailed explanation of the steps for django to display background table data in the front-end html page

##4. Visit the front page,

Detailed explanation of the steps for django to display background table data in the front-end html page

The above is the detailed content of Detailed explanation of the steps for django to display background table data in the front-end html page. 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