姜戈"App with label XYZ could not be found"



我已经解决了所有关于这个问题的各种问题,但没有一个解决了我的问题。 我正在开发一个django项目,其中包含最新版本的django,virtualenv,在装有Python 2.7的Windows 7家用计算机上。 该项目旨在在Heroku上启动,但它在本地也不起作用。

基本上,当尝试运行manage.py sqlall appname时,它总是返回以下错误树:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagement__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagement__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagementcommandstest.py", line 49, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagementbase.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagementbase.py", line 232, in execute
    output = self.handle(*args, **options)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagementcommandstest.py", line 72, in handle
    failures = test_runner.run_tests(test_labels)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
otestsimple.py", line 380, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
otestsimple.py", line 263, in build_suite
    app = get_app(label)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
odbmodelsloading.py", line 152, in get_app
    raise ImproperlyConfigured("App with label %s could not be found" % app_labe
l)
django.core.exceptions.ImproperlyConfigured: App with label tryagain could not b
e found

它甚至不会识别一个全新的、未受破坏的应用程序。 例如,如果我运行manage.py startapp tryagain然后将'tryagain'添加到INSTALLED_APPS,则在尝试类似manage.py test tryagain时仍然会收到相同的错误。 我的settings.py文件与普通文件不同的唯一原因是,对于 Heroku,我添加了以下两行:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}

任何帮助将不胜感激。 我在这里把自己逼疯了。

编辑:

首先,我尝试使用一个全新的应用程序启动一个全新的 Django 项目,它仍然不起作用,即使一切都完全没有受到影响。

由于我无法弄清楚哪些设置是相关的,因此我为我的麻烦项目提供了下面的整个settings.py模块:

# Django settings for <problem> project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
##DATABASES = {
##    'default': {
##        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
##        'NAME': '',                      # Or path to database file if using sqlite3.
##        'USER': '',                      # Not used with sqlite3.
##        'PASSWORD': '',                  # Not used with sqlite3.
##        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
##        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
##    }
##}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = ''
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'craigslist.urls'
TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #'kombu.transport.django',
    #'djcelery',
    '<problemappname>',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)
BROKER_BACKEND = 'django'
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
# note that this becomes the following:
# DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 
#                           'NAME': '',
#                           'HOST': 'localhost',
#                           'USER': None,
#                           'PASSWORD': None,
#                           'PORT':  None } }

附加编辑:目录结构可以在下面看到,注释在括号中。

 - craigslist (project)
     - craigslist
         - __init__.py
         - settings.py
         - urls.py
         - wsgi.py
     - venv (virtualenv)
         - Include (directory)
         - Lib (directory)
         - Scripts (directory)
     - webpage (app)
         - __init__.py
         - models.py
         - tests.py
         - views.py
     - __init__.py
     - listings.py (custom module, not touched yet)
     - manage.py
     - requirements.txt
     - settings.py
     - urls.py

第三次编辑:认为当我运行manage.py syncdb时,我会收到以下错误,这也可能有所帮助:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagement__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagement__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagementbase.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagementbase.py", line 232, in execute
    output = self.handle(*args, **options)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagementbase.py", line 371, in handle
    return self.handle_noargs(**options)
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
ocoremanagementcommandssyncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "C:UsersJJDocumentsCoding Funcraigslistvenvlibsite-packagesdjang
odbbackendsdummybase.py", line 15, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly co
nfigured. Please supply the ENGINE value. Check settings documentation for more
details.

另一个编辑:根据要求,这是我的models.py.

# models.py
from django.db import models
# Create your models here.
class listing(models.Model):
    body = models.CharField(max_length=10000)
    title = models.CharField(max_length=400)
    url = models.URLField(primary_key = True)
    scraping_time = models.DateTimeField()
    phone = models.CharField(max_length=20)
    posting_time = models.DateTimeField()
    email = models.EmailField()
    # imglist as separate model
    def __str__(self):
        return self.title
class imagelist(models.Model):
    listing = models.ForeignKey(listing)
    img_url = models.URLField()
    def __str__(self):
        return self.img_url

头疼过后,我才想通。

由于某种原因,有两个settings.py s——一个在整个项目目录craigslist,一个在子目录craigslistcraigslist,我正在编辑顶层settings.py,我应该编辑下层的。 我不知道这是为什么,但是将所有代码从顶层复制到子级别后,突然manage.py sqlall webpage工作了。

就我而言,我的问题是我修改了DJANGO_SETTINGS_MODULE,但仅在我的 gunicord 设置文件 (/webapps/run/gunicorn_start) 中更改了它。所以"python mange.py"仍然指的是旧的settings.pyc文件("py"文件已经被删除,但"pyc"仍然存在......

完成以下操作后,一切正常:导出DJANGO_SETTINGS_MODULE=...

相关内容

  • 没有找到相关文章

最新更新