将django部署到heroku:找不到页面错误


I have been making a django app, and am now trying to deploy it to heroku. However when I go on it,says page not found 
the resources not found on the server 

我正在不同的应用程序上尝试。错误保持不变这是我的设置.py(至少是相关部分,但请询问您是否想要其余部分(:"quot"Django_deployment项目的Django设置。

Generated by 'django-admin startproject' using Django 4.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
import os 
import django_heroku
import dj_database_url
from decouple import config
# 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/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['django-deployment85.herokuapp.com','127.0.0.1']

# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp'
]
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',
"whitenoise.middleware.WhiteNoiseMiddleware",
]
ROOT_URLCONF = 'django_deployment.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [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 = 'django_deployment.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}

# Password validation
# https://docs.djangoproject.com/en/4.0/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/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
#STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STATICFILES_STORAGE =  'django.contrib.staticfiles.storage.StaticFilesStorage'
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
django_heroku.settings(locals())

#and here is my requirement.txt 
asgiref==3.4.1
backports.entry-points-selectable==1.1.1
certifi==2021.10.8
distlib==0.3.4
dj-database-url==0.5.0
Django==4.0
django-heroku==0.3.1
filelock==3.4.0
gunicorn==20.1.0
pipenv==2021.11.23
platformdirs==2.4.0
psycopg2==2.9.3
python-decouple==3.6
six==1.16.0
sqlparse==0.4.2
tzdata==2021.5
virtualenv==20.10.0
virtualenv-clone==0.5.7
virtualenvwrapper-win==1.2.6
waitress==2.0.0
whitenoise==6.0.0

此外,当我使用python manage.py runserver在本地运行该应用程序时,它工作得很好,只有当我使用heroku时它才不工作。

如果你需要更多信息,请告诉我。

您可能在Heroku中有postgres,但您的settings.py显示您仍在使用SQLite。DATABASES部分应该看起来像:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name_goes_here',
'USER': 'username_goes_here',
'PASSWORD': 'password_goes_here',
'HOST': 'localhost',
'PORT': '',
}
}

数据库名称、用户和密码,您可以通过转到数据库,然后单击设置,然后单击凭据来获取。

在Heroku上部署Django有几个步骤。配置Postgres只是其中之一。上有一个很好的教程https://dev.to/giftedstan/heroku-how-to-deploy-a-django-app-with-postgres-in-5-minutes-5lk.

相关内容

最新更新