开始使用django和heroku,"应用程序错误"上传后

时间:2014-06-03 00:20:38

标签: python django heroku

  1. 我一直在使用本指南:https://devcenter.heroku.com/articles/getting-started-with-django
  2. requirements.txt

    Django==1.6.5
    argparse==1.2.1
    dj-database-url==0.3.0
    dj-static==0.0.5
    django-toolbelt==0.0.1
    gunicorn==18.0
    psycopg2==2.5.3
    pystache==0.5.4
    static==1.0.2
    wsgiref==0.1.2
    

    文件结构

       hellodjango
       ├── hellodjango
       │   ├── __init__.py
       │   ├── settings.py
       │   ├── settings.py~
       │   ├── urls.py
       │   ├── wsgi.py
       │   └── wsgi.py~
       └── manage.py
       1 directory, 7 files
    

    目录Projects / projects / 6.2.2014

    中的其他文件
        (venv)user@user-VirtualBox:~/Projects/projects/6.2.2014$ ls
        hellodjango  Procfile  Procfile~  requirements.txt  venv
    

    来自heroku日志的片段:

        2014-06-02T23:42:49.621172+00:00 app[web.1]: ImportError: No module named  
        hellodjango.wsgi
        2014-06-02T23:42:49.621171+00:00 app[web.1]:     __import__(module)
        2014-06-02T23:42:49.621219+00:00 app[web.1]: 2014-06-02 23:42:49 [7] [INFO] Worker
        exiting (pid: 7)
        2014-06-02T23:42:49.790790+00:00 app[web.1]: 2014-06-02 23:42:49 [2] [INFO] Shutting
        down: Master
        2014-06-02T23:42:51.344028+00:00 heroku[web.1]: Process exited with status 3
        2014-06-02T23:42:47.298345+00:00 heroku[web.1]: Starting process with command 
        `gunicorn hellodjango.wsgi`
        2014-06-02T23:42:51.355014+00:00 heroku[web.1]: State changed from starting to 
        crashed
        (venv)user@user-VirtualBox:~/Projects/projects/6.2.2014$ 
    

    Procfile

        web: gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT
    

    有人能指出我在这里缺少的方向吗? 当Procfile只有这个时,我访问我的网站时遇到了同样的“应用程序错误”:

    Procfile(旧)

        web: gunicorn hellodjango.wsgi
    

    设置文件

        # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
        import os
        BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    
    
        # Quick-start development settings - unsuitable for production
        # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
    
        # SECURITY WARNING: keep the secret key used in production secret!
        # I removed this line for the stack overflow posting SECRET_KEY = ''
    
        # SECURITY WARNING: don't run with debug turned on in production!
        DEBUG = True
    
        TEMPLATE_DEBUG = True
    
        ALLOWED_HOSTS = ['*']
    
    
        # Application definition
    
        INSTALLED_APPS = (
            'django.contrib.admin',
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
            'django.contrib.messages',
            'django.contrib.staticfiles',
            'gunicorn', #this wasn't here before, i added it and still got the application 
             # error
            )
    
        MIDDLEWARE_CLASSES = (
            '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 = 'hellodjango.urls'
    
        WSGI_APPLICATION = 'hellodjango.wsgi.application'
    
    
        # Database
        # https://docs.djangoproject.com/en/1.6/ref/settings/#databases
    
        """
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
            }
         }
        """
        # Internationalization
        # https://docs.djangoproject.com/en/1.6/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.6/howto/static-files/
    
        STATIC_URL = '/static/'
    
        # Parse database configuration from $DATABASE_URL
        import dj_database_url
        DATABASES['default'] =  dj_database_url.config()
    
        # Honor the 'X-Forwarded-Proto' header for request.is_secure()
        SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
    
    
        # Static asset configuration
        import os
        BASE_DIR = os.path.dirname(os.path.abspath(__file__))
        STATIC_ROOT = 'staticfiles'
        STATIC_URL = '/static/'
    
        STATICFILES_DIRS = (
            os.path.join(BASE_DIR, 'static'),
        )
    

    这是我目前在/Projects/projects/6.2.2014/hellodjango/hellodjango

    中的wsgi.py文件
        import os
        from django.core.wsgi import get_wsgi_application
        from dj_static import Cling
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellodjango.settings")
    
    
        application = Cling(get_wsgi_application())
    

2 个答案:

答案 0 :(得分:0)

将其添加到您的.wsgi文件

from django.core.wsgi import get_wsgi_application
from dj_static import Cling

application = Cling(get_wsgi_application())

答案 1 :(得分:0)

将您的wsgi.py文件更改为:

import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellodjango.settings")
from dj_static import Cling
application = Cling(get_wsgi_application())

您需要在导入Cling之前指定您的设置,否则会出错。