我想從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?
*是什麼*不對的代碼? – Sayse
這段代碼究竟有什麼問題。 –
[so]是爲了幫助解決問題,而不是猜測它們是什麼,你應該描述你正試圖解決的問題。 – Sayse