我想發送一個變量到使用Django表單和模板的HTML。Django - 診斷問題與類和視圖
這是我的代碼...
class AdminView(TemplateView):
template_name = 'admin.html'
def admin(self, request):
template = 'admin.html'
data = Quiz.objects.all()
form = AdminForm(request.POST)
context = {"form": form}
context['admin'] = data
# return render(request, template, context)
return render_to_response(context)
什麼是錯的代碼?變數怎麼沒有出現在網站上。
行上下文= {「form」,form}已經在我的IDE中高亮顯示,並且出錯。
錯誤:此字典創建可能被重寫爲字典文字。
這是怎麼回事?
class AdminView(TemplateView):
template_name = 'admin.html'
def post(self, request):
template = 'admin.html'
data = Quiz.objects.all()
form = AdminForm(request.POST)
context = {"form": form}
context['admin'] = data
return render(request, template, context)
不幸的是仍然無法正常工作?
這是HTML代碼...
{% 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
{{ admin }}
</body>
</html>
{% endif %}
好的,我已經添加了一些問題。這看起來如何?它似乎還沒有工作。 –