Django Model类app.models.tasks未声明显式app_label,也不在INSTALLED_APPS中的应用程序中

时间:2019-11-11 11:33:44

标签: django

我为我的Django网站拥有此视图和模型设置。

运行页面时,出现以下错误,我也不知道为什么!

如果有人可以推荐我可以解决的问题,我将非常感激!

任何人都可以帮忙吗?

'Model class app.models.tasks doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

这是代码

from __future__ import unicode_literals
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
from django.http import *
from django.shortcuts import render_to_response,redirect
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserChangeForm
from django.db.models import Q
from django.db.models import Count
from datetime import datetime
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.forms import PasswordChangeForm
from datetime import date
from .models import tasks

def create_task(request):
    if request.method == 'POST':
        creator = request.user
        job_title = request.POST.get('job_title')
        skill_name = request.POST.get('skill_name')
        starting = request.POST.get('starting')
        description = request.POST.get('description')
        target_date = request.POST.get('target_date')
    i = tasks.objects.create(creator=creator, job_title=job_title, skill_name=skill_name,  starting=starting, current=starting, description=description, target_date=target_date)
    messages.success(request, ('Skill created'))
    return redirect('index')

我有这个模型:

from django.db import models

class tasks(models.Model):
    job_title = models.CharField(max_length=400, default="none")
    creator = models.CharField(max_length=400, default="none")
    skill_name = models.CharField(max_length=400)
    starting = models.CharField(max_length=400, default="none")
    current = models.CharField(max_length=400, default="none")
    description = models.CharField(max_length=4000000, default="none")
    target_date = models.CharField(max_length=400, default="none")
    def __str__(self):
        return self.text

1 个答案:

答案 0 :(得分:1)

根据上面的注释,当配置了新应用但不属于INSTALLED_APPSsettings.py的一部分时,就会发生此错误