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)
何...私のコードですか?どのように変数がウェブサイトに表示されないのでしょうか。
私のIDEでline context = {"form"、form}がハイライトされ、エラーが発生しました。
エラー:この辞書の作成は、辞書のリテラルとして書き直すことができます。
これはどのように見えるのですか?
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)
残念ながらまだ動作しませんか?
これは...単にスタイルの問題であり、実際の問題とは何の関係もありません
{% 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 %}
私は質問に少し追加しました。それはどうやって見える?それはまだ動作していないようです。 –