Django - AttributeError在/ 'tuple'对象没有属性'get'

2sbarzqh  于 2023-01-14  发布在  Go
关注(0)|答案(1)|浏览(159)

我在以下位置收到属性错误:

Exception Location: C:\Users\user\Desktop\django-basics\env\lib\site-packages\django\middleware\clickjacking.py, line 26, in process_response

这是所述位置(process_response函数):

def process_response(self, request, response):
    # Don't set it if it's already in the response
    if response.get('X-Frame-Options') is not None:
        return response

我的视图文件

from django.shortcuts import render
from .models import Student
def studentlist(request):
    get_students = Student.objects.all()

    data = {
        'get_students' : get_students
    }
    return render(request, 'studentlist.html', data)

我的模板文件studentlist.html:

{% load static %}
 
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" />
<title>Student List</title>
</head>
<body>
<div class="container">
  <h2 class="text-center mt-5">Student List</h2>
  <table class="table table-hover table-dark">
    <thead>
      <tr>
        <th scope="col">Roll No.</th>
        <th scope="col">Photo</th>
        <th scope="col">Full Name</th>
        <th scope="col">Gender</th>
        <th scope="col">Course</th>
        <th scope="col">Grade in course</th>
      </tr>
    </thead>
    <tbody>
      {% for student in get_students %}
      <tr>
        <td>{{ student.roll_no }}</td>
        <td>
          <img src="{{ student.photo.url }}" width="40" height="40"/>
        </td>
        <td>{{ student.full_name }}</td>
        <td>{{ student.course }}</td>
        <td>{{ student.grade }}</td>
        <td>{{ student.gender }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</div>

请让我知道,如果我需要添加更多的信息。提前感谢。

zzlelutf

zzlelutf1#

如果有人有同样的问题,威廉·货车·翁塞姆的回答解决了我的问题,最后我昏迷了。

相关问题