我创建了一个 django 软件,它在 localhost 上运行,但不能在 heroku 上工作,它的日志显示了这个

Posted

技术标签:

【中文标题】我创建了一个 django 软件,它在 localhost 上运行,但不能在 heroku 上工作,它的日志显示了这个【英文标题】:i created a django software its running on localhost,but not working on heroku its log is showing this 【发布时间】:2021-03-11 09:35:27 【问题描述】:

我在日志文件中收到以下错误。下面添加了项目目录树、settings.py 和 Procfile。我该如何解决。

所有项目文件都在ShubhamSjain2000/stockware

日志错误:

2020-11-28T07:50:10.254987+00:00 app[api]: Release v4 created by user shubham1900jain@gmail.com
2020-11-28T07:50:10.531132+00:00 app[api]: Deploy d9583d0a by user shubham1900jain@gmail.com
2020-11-28T07:50:10.531132+00:00 app[api]: Release v5 created by user shubham1900jain@gmail.com
2020-11-28T07:50:20.000000+00:00 app[api]: Build succeeded
2020-11-28T07:50:35.159601+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=stockware.herokuapp.com request_id=0b1c2b67-1ac9-4247-8f90-fb928da59cd6 fwd="182.70.189.243" dyno= connect= service= status=503 bytes= protocol=https
2020-11-28T07:50:36.170169+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=stockware.herokuapp.com request_id=af302f4c-e5cc-405e-ba97-30a07516c784 fwd="182.70.189.243" dyno= connect= service= status=503 bytes= protocol=https
2020-11-29T04:12:18.801989+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=stockware.herokuapp.com request_id=e9644275-2548-4405-8dab-7f58291c79ec fwd="182.70.190.109" dyno= connect= service= status=503 bytes= protocol=https
2020-11-29T04:12:23.337106+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=stockware.herokuapp.com request_id=54638bf1-67b2-4982-8e2c-365826a046f2 fwd="182.70.190.109" dyno= connect= service= status=503 bytes= protocol=https
2020-11-29T04:19:50.571393+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=stockware.herokuapp.com request_id=ac335c25-ed5e-4faa-909d-9208375721f7 fwd="182.70.190.109" dyno= connect= service= status=503 bytes= protocol=https
2020-11-29T04:19:51.945843+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=stockware.herokuapp.com request_id=ba9f09fb-8aff-4096-af16-cb673534520e fwd="182.70.190.109" dyno= connect= service= status=503 bytes= protocol=https

项目目录树

- accounts/
   - admin.py
   - apps.py
   - models.py
   - tests.py
   - urls.py
   - views.py
- assets/
- price/
   - admin.py
   - apps.py
   - models.py
   - tests.py
   - urls.py
   - views.py
- static/
   - contact.html
   - home.html
   - money.jpg
   - navbar.html
   - profile.html
   - scripts.html
- stock/
   - asgi.py
   - settings.py
   - urls.py
   - wsgi.py
- templates/
   - app.html
   - contact.html
   - globalindices.html
   - holdings.html
   - index.html
   - login.html
   - profile.html
   - register.html
   - research.html
   - scripts.html
- Procfile
- db.sqlite3
- manage.py
- requirements.txt
- stock.sqlite3

下面是设置文件。

stock/settings.py

DEBUG = False

ALLOWED_HOSTS = ['*']

INSTALLED_APPS = [
    'accounts.apps.AccountsConfig',
    'price.apps.PriceConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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 = 'stock.urls'

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 = 'stock.wsgi.application'

DATABASES = 
    'default': 
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'stock.sqlite3',
    


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',
    ,
]

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'
STATICFILES_DIRS =[ os.path.join(BASE_DIR,'static')]
STATIC_ROOT = os.path.join(BASE_DIR,'assets')

下面是我的 Procfile。

过程文件

web: gunicorn STOCK.wsgi --log-file -

【问题讨论】:

这能回答你的问题吗? No web processes running Error - Deploying Django on Heroku 您是否能够使用下面显示的任何答案来解决这个问题?如果是这样,请记得accept it。这会向其他用户显示您找到了解决方案。 【参考方案1】:

我很惊讶您没有收到更多有用的错误消息。一个问题是您将 Gunicorn 指向一个名为 STOCK.wsgi 的模块,但您的模块实际上名为 stock.wsgi

相应地更改您的Procfile

web: gunicorn stock.wsgi --log-file -

【讨论】:

以上是关于我创建了一个 django 软件,它在 localhost 上运行,但不能在 heroku 上工作,它的日志显示了这个的主要内容,如果未能解决你的问题,请参考以下文章

当使用 chrome POSTMAN 测试 http POST 时,它在 django 中不起作用

运行这个 django 项目,但它在 manage.py 中向我显示了这个错误

Django 中的 Ajax 正在创建重复元素

Django使用transaction.atomic“死锁”

如何确保我的Django项目正在使用我为其创建的虚拟环境?

Django:带有附加列的 ManyToManyField