RuntimeError:模型类django.contrib.contenttypes.models.ContentType没有声明

时间:2017-08-10 10:37:55

标签: python django

我正在尝试运行以下命令

$ python app_ac/cron_scripts.py

错误

  File "app_ac/cron_scripts.py", line 15, in <module>
    from django.contrib.auth.models import User
  File "/usr/lib/python2.7/site-packages/django/contrib/auth/models.py", line 6, in <module>
    from django.contrib.contenttypes.models import ContentType
  File "/usr/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 138, in <module>
    class ContentType(models.Model):
  File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 113, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

cron_scripts.py

import os
import re
import sys
import argparse
from os.path import expanduser
from os.path import join
from os.path import basename
from os.path import splitext
from datetime import datetime
import django
from django.conf import settings

settings.configure()
django.setup()
from django.contrib.auth.models import User
import time

def update_cron():
    us = User.objects.get(username='onkar')
    now = datetime.now()
    us.first_name = now.strftime("%d%m%Y %H:%M")
    us.save()



update_cron()

settings.py

应用程序定义

INSTALLED_APPS = [
    'django.contrib.contenttypes',
    'django.contrib.admin',
    'django.contrib.auth',
    #'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'guardian',
    'django_tables2',
    'crispy_forms',
    'adminlte_full',
    'wkhtmltopdf',
    'docs',
    'app_ac',
]
#import django
#django.setup()
#SITE_ID = 1

0 个答案:

没有答案