将测试站点部署到 heroku 后,它显示一个 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<p>first box here:</p>
<select id="list1" onchange="fn1();">
<option value ="car1000">Audi A2 (2001)</option>
<option value ="car1010">Audi A3 (2004)</option>
<option value ="car1020">Audi A5 (2009)</option>
</select>
<div id="list2"><p>second box here:</p></div>
<script>
$( "#list1" ).clone().appendTo( "#list2");
</script>
<script>
function fn1(){
selectedValueCar = document.getElementById("list1").value;
console.log(selectedValueCar);
selectedValueCar2 = document.getElementById("list2").value;
console.log(selectedValueCar2);
}
</script>
</body>
</html>
:
Application Error
:
Heroku Log
这似乎是问题所在:
2021-06-25T13:20:42.143490+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-25T13:20:42.143491+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-25T13:20:42.143492+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-25T13:20:42.143492+00:00 app[web.1]: self.callable = self.load()
2021-06-25T13:20:42.143492+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-25T13:20:42.143493+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-25T13:20:42.143493+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-25T13:20:42.143494+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-25T13:20:42.143494+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-25T13:20:42.143494+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-25T13:20:42.143495+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-25T13:20:42.143495+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-25T13:20:42.143496+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-25T13:20:42.143496+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-25T13:20:42.143496+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-06-25T13:20:42.143497+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-06-25T13:20:42.143497+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2021-06-25T13:20:42.143498+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-25T13:20:42.143498+00:00 app[web.1]: File "/app/config/wsgi.py", line 12, in <module>
2021-06-25T13:20:42.143498+00:00 app[web.1]: from django.core.wsgi import get_wsgi_application
2021-06-25T13:20:42.143499+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2021-06-25T13:20:42.144378+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-06-25T13:20:42.184157+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [9] [INFO] Booting worker with pid: 9
2021-06-25T13:20:42.220213+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [9] [ERROR] Exception in worker process
2021-06-25T13:20:42.220214+00:00 app[web.1]: Traceback (most recent call last):
2021-06-25T13:20:42.220215+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-25T13:20:42.220216+00:00 app[web.1]: worker.init_process()
2021-06-25T13:20:42.220216+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-25T13:20:42.220216+00:00 app[web.1]: self.load_wsgi()
2021-06-25T13:20:42.220217+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-25T13:20:42.220217+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-25T13:20:42.220218+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-25T13:20:42.220218+00:00 app[web.1]: self.callable = self.load()
2021-06-25T13:20:42.220219+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-25T13:20:42.220219+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-25T13:20:42.220220+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-25T13:20:42.220220+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-25T13:20:42.220220+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-25T13:20:42.220221+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-25T13:20:42.220221+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-25T13:20:42.220222+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-25T13:20:42.220222+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-25T13:20:42.220222+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-25T13:20:42.220223+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-06-25T13:20:42.220223+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-06-25T13:20:42.220224+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2021-06-25T13:20:42.220224+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-25T13:20:42.220224+00:00 app[web.1]: File "/app/config/wsgi.py", line 12, in <module>
2021-06-25T13:20:42.220225+00:00 app[web.1]: from django.core.wsgi import get_wsgi_application
2021-06-25T13:20:42.220225+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2021-06-25T13:20:42.222244+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-06-25T13:20:42.237399+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [4] [WARNING] Worker with pid 9 was terminated due to signal 15
2021-06-25T13:20:42.341186+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [4] [INFO] Shutting down: Master
2021-06-25T13:20:42.382466+00:00 app[web.1]: [2021-06-25 13:20:42 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-06-25T13:20:42.762358+00:00 heroku[web.1]: Process exited with status 3
2021-06-25T13:20:42.868448+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-25T13:20:42.872437+00:00 heroku[web.1]: State changed from crashed to starting
2021-06-25T13:20:50.974740+00:00 heroku[web.1]: Starting process with command `gunicorn config.wsgi --log-file -`
2021-06-25T13:20:53.577634+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-06-25T13:20:53.578269+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Listening at: http://0.0.0.0:13141 (4)
2021-06-25T13:20:53.578415+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Using worker: sync
2021-06-25T13:20:53.583477+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [8] [INFO] Booting worker with pid: 8
2021-06-25T13:20:53.588859+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [8] [ERROR] Exception in worker process
2021-06-25T13:20:53.588860+00:00 app[web.1]: Traceback (most recent call last):
2021-06-25T13:20:53.588860+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-25T13:20:53.588861+00:00 app[web.1]: worker.init_process()
2021-06-25T13:20:53.588861+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-25T13:20:53.588861+00:00 app[web.1]: self.load_wsgi()
2021-06-25T13:20:53.588861+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-25T13:20:53.588862+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-25T13:20:53.588862+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-25T13:20:53.588862+00:00 app[web.1]: self.callable = self.load()
2021-06-25T13:20:53.588862+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-25T13:20:53.588863+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-25T13:20:53.588863+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-25T13:20:53.588863+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-25T13:20:53.588864+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-25T13:20:53.588864+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-25T13:20:53.588864+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-25T13:20:53.588864+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-06-25T13:20:53.588865+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2021-06-25T13:20:53.588866+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-25T13:20:53.588866+00:00 app[web.1]: File "/app/config/wsgi.py", line 12, in <module>
2021-06-25T13:20:53.588866+00:00 app[web.1]: from django.core.wsgi import get_wsgi_application
2021-06-25T13:20:53.588866+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
2021-06-25T13:20:53.588953+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-06-25T13:20:53.613376+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Shutting down: Master
2021-06-25T13:20:53.613444+00:00 app[web.1]: [2021-06-25 13:20:53 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-06-25T13:20:53.666415+00:00 heroku[web.1]: Process exited with status 3
2021-06-25T13:20:53.736085+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-25T13:21:03.827606+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=infinite-lake-64780.herokuapp.com request_id
=ebdb0566-934d-42f3-8406-3c22ad946ffe fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:21:04.056665+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=infinite-lake-64780.herokuapp.com
request_id=f39bf025-1373-4119-8d11-bad44e3a7a1d fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:25:13.778941+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=infinite-lake-64780.herokuapp.com request_id
=cf9fc6eb-e3e5-4028-aec6-b06ebd759654 fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:25:14.062569+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=infinite-lake-64780.herokuapp.com
request_id=244089c9-a74f-4fbb-a4cf-88efd26bf187 fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:29:24.973091+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=infinite-lake-64780.herokuapp.com request_id
=161fe80f-f695-4eff-873f-a99576f5eb6b fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
2021-06-25T13:29:25.244494+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=infinite-lake-64780.herokuapp.com
request_id=702bd951-0a20-47c3-9c2f-8bbefc77379f fwd="91.23.54.245" dyno= connect= service= status=503 bytes= protocol=https
这是2021-06-25T13:20:53.588866+00:00 app[web.1]: ModuleNotFoundError: No module named 'django'
:
root dir
:
config/settings.py
"""
Django settings for config project.
Generated by 'django-admin startproject' using Django 3.2.4.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'security__key'
# SECURITY WARNING: don't run with debug turned on in production!
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',
'pages',
]
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 = 'config.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [str(BASE_DIR.joinpath('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 = 'config.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/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/3.2/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/3.2/howto/static-files/
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
:
Procfile
web: gunicorn config.wsgi --log-file -
:
Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
gunicorn = "*"
[dev-packages]
[requires]
python_version = "3.8"
:
requirements.txt
gunicorn
:
runtime.txt
答案 0 :(得分:0)
问题是 Django 不在您的 requirements.txt
文件中。您必须在 requirements.txt
文件中包含您使用的所有模块。
要解决此问题,请更改您的 requirements.txt 文件以包含 Django(以及您使用的任何其他模块)
您的 requirements.txt 文件应如下所示(如果您没有任何其他模块):
django
gunicorn
如果您仍然遇到相同的错误,请删除您的 Pipfile,并确保您已通过 git 暂存、提交并推送您的更改到 Heroku。
要暂存、提交和推送,请在命令行中执行以下操作(确保您位于应用程序目录中)
暂存您的更改:
git add .
提交更改:
git commit -m 'Updated requirements.txt'
要将您的更改推送到 Heroku:
git push heroku master
答案 1 :(得分:0)
多亏了 ENDESSA 的评论,我才能够解决这个问题。我在 requirements.txt vs Pipfile in heroku flask webapp deployment? 中找到了解决方案。
Pipfile
和 requirements.txt
似乎有问题。当您设置 pipenv
时,它会创建 Pipfile
并忽略 requirements.txt
。我的问题是我在 Pycharm 中设置了 venv
并安装了 pipenv
,这会导致错误。删除 Pipfile
后,我的测试站点正常运行。
我还必须设置 heroku config:set DISABLE_COLLECTSTATIC=1
,但我不确定是否还需要 heroku ps:scale web=1
。
Anyhoo,非常感谢