嗨,我已经完成了我的Django pycharm项目,我现在正试图将它上传到heroku/heroku上。我一直在关注这个链接https://medium.com/@qazi/how-to-deploy-a-django-app-to-heroku-in-2018-the-easy-way-48a528d97f9c,这在过去实际上已经成功地为我工作了。当我到达这个步骤时,你把这个命令放在'heroku run python management .py migrate'中,我继续得到这个错误信息'在如可答:radian - reversion -19016上运行python management .py migrate…, run.6371(免费)python:无法打开文件'manage.py': [Errno 2]没有这样的文件或目录'我不是一个初学者,所以我知道我的manage.py文件在正确的地方,特别是因为我可以运行' python manage.py runserver '。我将把代码附加到下面我的procFile以及我的manage.py代码和设置。我在互联网上到处寻找这个问题,有些人有这个问题,但没有任何方法对他们有效。我会附上任何其他代码,如果你需要它。我甚至把所有的代码转移到一个新的项目,同样的问题发生了。
web: gunicorn inspect_list2.wsgi
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inspect_list2.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
"""
Django settings for inspect_list project.
Generated by 'django-admin startproject' using Django 2.2.14.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
import django_heroku
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'not showing this but its there'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'my_app',
#'auth',
]
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 = 'inspect_list2.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'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 = 'inspect_list2.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/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/2.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/2.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/2.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
AUTH_USER_MODEL = 'my_app.CustomUser'
LOGIN_REDIRECT_URL = 'front_page'
LOGOUT_REDIRECT_URL = 'home'
django_heroku.settings(locals())
修复
heroku run python **FOLDER**/manage.py migrate
交货
heroku run python HOME/manage.py migrate
10个小时后我终于弄明白了。网上的其他消息来源是对的。如果你参考我在最底部的命令上面发布的链接。如果你先运行git push命令,然后再运行heroku migrate命令,就可以了。等等!如果它不起作用,那么如果你碰了git仓库的东西,或者改变了名字,或者弄乱了你的squilte3文件,你不知道你在做什么,那么把你所有的代码转移到另一个项目中,这样git的东西和squilte3的东西就会自动生成并重置,然后再按照这个注释中的说明进行操作。如果不是,我不知道该告诉你什么,但它对我有效。
你可以试试这个。右键单击manage.py文件,并在再次运行代码时查找open in terminal选项