2017-12-27 28 views
1

Ich habe eine einfache Django Web App erstellt. Wenn ich die models.py-Datei ausführe, erhalte ich den folgenden Fehler. Ich habe eine Reihe von Lösungen ausprobiert, darunter das Entfernen meiner Apps nacheinander, das erneute Installieren von django (ich habe Version 2.0), einen alten Systemneustart, Einfügen von import django + django.setup(), das Aktualisieren des virtualenv.Super einfach Tutorial werfen django.core.exceptions.AppRegistryNotReady: Apps sind noch nicht geladen

Traceback (most recent call last): 
File "C:/Users/Pritee/djangogirls/blog/models.py", line 6, in <module> 
class Post(models.Model): 
File "C:\Users\Pritee\djangogirls\myvenv\lib\site- 
packages\django\db\models\base.py", line 100, in __new__ 
app_config = apps.get_containing_app_config(module) 
File "C:\Users\Pritee\djangogirls\myvenv\lib\site- 
packages\django\apps\registry.py", line 244, in get_containing_app_config 
self.check_apps_ready() 
File "C:\Users\Pritee\djangogirls\myvenv\lib\site- 
packages\django\apps\registry.py", line 127, in check_apps_ready 
raise AppRegistryNotReady("Apps aren't loaded yet.") 
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. 

Models.py

from django.db import models 

from django.utils import timezone 


class Post(models.Model): 
    author = models.ForeignKey('auth.User',on_delete=models.CASCADE) 
    title = models.CharField(max_length=200) 
    text = models.TextField() 
    created_date = models.DateTimeField(
      default=timezone.now) 
published_date = models.DateTimeField(
     blank=True, null=True) 

def publish(self): 
    self.published_date = timezone.now() 
    self.save() 

def __str__(self): 
    return self.title 

Settings.py

import os 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = 'iua)_567ww!*c9#dhg#f&u4ft$([email protected]!$ro=^+u!+t' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

ALLOWED_HOSTS = ['127.0.0.1'] 


# Application definition 

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

MIDDLEWARE = [ 
'django.middleware.security.SecurityMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.middleware.clickjacking.XFrameOptionsMiddleware', 
] 

ROOT_URLCONF = 'mysite.urls' 

TEMPLATES = [ 
{ 
    'BACKEND': 'django.template.backends.django.DjangoTemplates', 
    'DIRS': [], 
    'APP_DIRS': True, 
    'OPTIONS': { 
     'context_processors': [ 
      'django.template.context_processors.debug', 
      'django.template.context_processors.request', 
      'django.contrib.auth.context_processors.auth', 
      'django.contrib.messages.context_processors.messages', 
     ], 
    }, 
}, 
] 

WSGI_APPLICATION = 'mysite.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases 

DATABASES = { 
'default': { 
    'ENGINE': 'django.db.backends.sqlite3', 
    'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 


# Password validation 
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password- 
validators 

AUTH_PASSWORD_VALIDATORS = [ 
{ 
    'NAME': 
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 
}, 
{ 
    'NAME': 
'django.contrib.auth.password_validation.MinimumLengthValidator', 
}, 
{ 
    'NAME': 
'django.contrib.auth.password_validation.CommonPasswordValidator', 
}, 
{ 
    'NAME': 
'django.contrib.auth.password_validation.NumericPasswordValidator', 
}, 
] 


# Internationalization 
# https://docs.djangoproject.com/en/2.0/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/2.0/howto/static-files/ 

STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(BASE_DIR, 'static') 

command prompt Fehlertrace Bild


Mein Repo ist here: (es etwas anders Namensgebung hat, da ich das Tutorial versuchte es noch einmal von Grund auf zu tun, um zu sehen, ob ich es beheben könnte)


+0

Können Sie zeigen, die Sie Befehl an das Terminal läuft und von dem Pfad? –

+0

Was meinen Sie mit "run models.py file"? – oxalorg

+0

@oxalorg - In pycharm, führe ich die models.py Datei innerhalb meiner "Blog" -Anwendung aus. – Pri

Antwort

0

Ich glaube, du hast Post eine Vertiefung Fehler in Zeile 6 der Klasse. Verwenden Sie einfach einen Tab vor dem Veröffentlichungsdatum.

Versuchen Sie dies in Ihrem models.py

class Post(models.Model): 
    author = models.ForeignKey('auth.User',on_delete=models.CASCADE) 
    title = models.CharField(max_length=200) 
    text = models.TextField() 
    created_date = models.DateTimeField(default=timezone.now) 
    published_date = models.DateTimeField(blank=True, null=True) 
+0

@apron - danke, ich habe das Update gemacht, aber schien keinen Einfluss zu haben (immer noch den Fehler zu werfen). Es ist in der Zeile "Klasse Post (models.Model)": – Pri

+0

von Ihrem models.py Es schien das Problem. Aber wenn es das Problem nicht löst, können Sie Ihr Projekt @ github teilen und den Link hier teilen, damit jemand Ihr Projekt überprüfen kann. :) – Apon

+0

Mein Repo ist hier: https://github.com/PriteeTem/events (Es hat etwas andere Namen, seit ich versuchte, das Tutorial wieder von Grund auf neu zu tun, um zu sehen, ob ich es beheben könnte) – Pri

Verwandte Themen