在将新的类添加到models中时,Django模型类出现错误。

16 浏览
0 Comments

在将新的类添加到models中时,Django模型类出现错误。

我有以下代码:\nmodels.py\n

    from django.db import models
    class Title(models.Model):
        title_name = models.CharField(max_length=200)
        category = models.CharField(max_length= 30)
    class Tags(models.Model):
        tag1 = models.CharField(max_length=15)
        tag2 = models.CharField(max_length=15)
        tag3 = models.CharField(max_length=15)
        tag4 = models.CharField(max_length=15)
    class Videos:
        primo: str

\nviews.py\n

    from django.shortcuts import render, HttpResponse
    from django.http import HttpResponse
    from .models import Videos
    def home(request):
        vid = Videos()
        vid.primo = 'https://www.youtube.com/'
        return render(request, 'index.html', {'vid': vid})

\nsettings.py\n

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
    ]

\n当我运行服务器时,我得到的错误是:RuntimeError: Model class home.models.Title doesn\'t declare an explicit app_label and isn\'t in an application in INSTALLED_APPS.\n在只使用以下代码时,一切正常:\n

    def home(request):
        return render(request, 'index.html')

\n我不明白我应该在INSTALLED_APPS中指定什么,因为我只是添加了一个新的def来在我的HTML中呈现视频URL。为什么会出现这个错误?\n谢谢!

0