前端写的html通过django接收不到后台mysql的数据
相关代码
all_book.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>查看所有书籍</title>
</head>
<body>
<table border="1">
<tr>
<th>id</th>
<th>title</th>
<th>pub</th>
<th>price</th>
<th>info</th>
<th>market_price</th>
<th>op</th>
</tr>
{% for book in all_book %}
<tr>
<td>{{ book.id }}</td>
<td>{{ book.title }}</td>
<td>{{ book.pub }}</td>
<td>{{ book.info }}</td>
<td>{{ book.price }}</td>
<td>{{ book.market_price }}</td>
<td>
<a href="/bookstore/update_book/{{ book.id }}">更新</a>
<a href="">删除</a>
</td>
</tr>
{% endfor %}
</table>
</body>
</html>
views.py
def all_book(request):
a11_book = Book.objects.all()
# a11_book = a11_book.encode('utf-8').decode('utf-8')
# a11_book = a11_book.encode(errors='replace')
return render(request, 'bookstore/all_book.html', locals())
主路由urls.py
from django.contrib import admin
from django.urls import path, re_path, include
from .import views
urlpatterns = [
# 数据库查询视图,主路由配分发
path('bookstore/', include('bookstore.urls'))
]
分支路由bookstore/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('all_book', views.all_book),
]
没有报错,但网页显示不出数据库的数据,前端页面也只是简单地显示{{ book.id }},没有显示参数值,请各位帮帮忙!