0

这是我每次打开它时我部署的站点中的错误

Environment:


Request Method: GET
Request URL: http://skinproject.herokuapp.com/

Django Version: 1.9
Python Version: 2.7.13
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes', 
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles'] ##skindisease not included here :(
Installed 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.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/app/.heroku/miniconda/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  134.                 resolver_match = resolver.resolve(request.path_info)

File "/app/.heroku/miniconda/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  374.             for pattern in self.url_patterns:

File "/app/.heroku/miniconda/lib/python2.7/site-packages/django/utils/functional.py" in __get__
  33.         res = instance.__dict__[self.name] = self.func(instance)

File "/app/.heroku/miniconda/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  417.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

File "/app/.heroku/miniconda/lib/python2.7/site-packages/django/utils/functional.py" in __get__
  33.         res = instance.__dict__[self.name] = self.func(instance)

File "/app/.heroku/miniconda/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  410.             return import_module(self.urlconf_name)

File "/app/.heroku/miniconda/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)

File "/app/skindisease/urls.py" in <module>
  4. from .views import (

File "/app/skindisease/views.py" in <module>
  16. from .forms import PostForm

File "/app/skindisease/forms.py" in <module>
  4. from .models import skindisease

File "/app/skindisease/models.py" in <module>
  14. class skindisease(models.Model):

File "/app/.heroku/miniconda/lib/python2.7/site-packages/django/db/models/base.py" in __new__
  103.                         "application was loaded. " % (module, name))

Exception Type: RuntimeError at /
Exception Value: Model class skindisease.models.skindisease doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. 

在已安装的应用程序中:部分我看不到我在 django 中创建的应用程序,它是皮肤病应用程序。这是我的 settings.py 配置

# -*- coding: utf-8 -*-
"""
Django settings for projectdesign project.

Generated by 'django-admin startproject' using Django 1.9.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

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



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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secretkey'

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

ALLOWED_HOSTS = ['www.projectdesign.co', 'projectdesign.co', 'skinproject.herokuapp.com', 'https://skinproject.herokuapp.com/']


# Application definition

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

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

ROOT_URLCONF = 'projectdesign.urls'
ROOT_HOSTCONF = 'projectdesign.hosts'
DEFAULT_HOST = 'www'
DEFAULT_REDIRECT_URL = "http://www.projectdesign.com"
PARENT_HOST = "projectdesign.com"

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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 = 'projectdesign.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/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/1.9/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/1.9/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/1.9/howto/static-files/

STATIC_URL = '/static/'


STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    #'/var/www/static',

]

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")

MEDIA_URL = "/media_cdn/"
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media_cdn")

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

我已经在 INSTALLED_APPS 上包含了我的皮肤病应用程序,但在 heroku 中它没有?我在这里想念什么?

这是我的models.py

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.core.urlresolvers import reverse

# Create your models here.
def upload_location(instance, filename):
    #filebase, extension = filename.split(".")
    #filebase, extension = filename.split(".")
    #return "%s/%s.%s" %(instance.id, instance.id, extension)
    return "%s" %(filename)

class Post(models.Model):
    title = models.CharField(max_length=120)
    image = models.ImageField(upload_to=upload_location, 
            null=True, 
            blank=True, 
            width_field="width_field", 
            height_field="height_field",)
    width_field = models.IntegerField(default=0)
    height_field = models.IntegerField(default=0)
    content = models.TextField()
    updated = models.DateTimeField(auto_now=True, auto_now_add=False)
    timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)


#   def __str__(self):
#       return self.title

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("skindisease:update", kwargs={"id": self.id})

    class Meta:
        ordering = ["-timestamp", "-updated"]

这是我的manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projectdesign.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

这是我的 urls.py

from django.conf.urls import url
from django.contrib import admin

from .views import (
    post_list,
    post_create,
    post_detail,
    post_update,
    post_delete,
    )

urlpatterns = [
    url(r'^$', post_create),
    url(r'^(?P<id>\d+)/$', post_detail, name="detail"),
    url(r'^(?P<id>\d+)/edit/$', post_update, name="update"),
    url(r'^(?P<id>\d+)/delete/$', post_delete),
    #url(r'^skindisease/$', "<appname>.views.<function_name>"),
]
4

0 回答 0