1

我对 Django 3.1 版本知之甚少,我也是初学者。我已经尝试但未能解决此错误。所以需要帮助解决,

app文件夹下的views.py文件:

    from django.shortcuts import render
    from django.http import HttpResponse
    from musicianapp.models import Musician, Album
    
    # Create your views here.
    async def index(request):
        # await asyncio.sleep(0.5)
        musician_list = Musician.objects.order_by("first_name")
        diction = {'text_1': "This is a list of Musician !", 'musician':musician_list}
        return render(request, 'musicianapp/index.html', context=diction)

模板文件夹下的index.html :

  <!DOCTYPE html>
  {% load static %}
  <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Musician List</title>
      <link rel="stylesheet" href="{%static 'css/style.css'%}">
    </head>
    <body>
      {{text_1}}
      <table border="1">
        <tr>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Twitter Handle</th>
          <th>Country Name</th>
          <th>Followers</th>
          <th>Following</th>
          <th>Total Tweets</th>
          <th>Month on Tweets</th>
        </tr>
        {% for i in musician %}
        <tr>
          <td>{{ i.first_name}}</td>
          <td>{{ i.last_name}}</td>
          <td>{{ i.twitter_handle}}</td>
          <td>{{ i.country_name}}</td>
          <td>{{ i.followers}}</td>
          <td>{{ i.following}}</td>
          <td>{{ i.total_tweets}}</td>
          <td>{{ i.month_on_tweets}}</td>
        </tr>
        {% endfor %}
      </table>
    </body>
  </html>

以下是我得到的错误: 错误图片

4

0 回答 0