【发布时间】:2016-08-07 03:03:41
【问题描述】:
我正在尝试从 django 数据库中检索多条记录以显示在网页上的表格中。
这是我目前的代码...
class AdminView(TemplateView):
template_name = 'admin.html'
print("hello world")
def get(self, request):
template = 'admin.html'
data = str(Quiz.objects.all())
admin = AdminForm(request.GET)
context = {"admin": admin}
context['data'] = data
return render(request, template, context)
这是目前为止的网页...
{% if request.user.is_authenticated%}
{% if request.user.username == "teacher" %}
<!DOCTYPE html>
<html lang="en">
<head>
{% load staticfiles %}
<meta charset="UTF-8">
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}" />
</head>
<body>
{% include 'navbar.html' %}
Admin Test
{{ data }}
</body>
</html>
{% endif %}
{% endif %}
{% if not request.user.is_authenticated %}
<h2>Login Required</h2>
{% endif %}
您认为这段代码有什么问题?如何让它显示 str?
【问题讨论】:
-
这段代码有什么问题?
-
这段代码到底有什么问题。
-
Stack Overflow 用于帮助解决问题,而不是猜测它们是什么,您应该描述您要解决的问题。
-
我正在尝试从 django 数据库中检索多条记录以显示在网页上的表格中。
标签: django django-models