2014-07-19 95 views
0

我已经完成了我用Django制作的网站,并且希望能够将它加入进来。我发现Heroku,看到这是免费的,我的基本需求,并希望在那里举办。我的网站使用SQLite而不是PostgreSQL,所以我想知道如何使用它,因为它不支持sqlite。我发现在Heroku上开始使用Django页面,但我没有使用pip或virtualenv来设置它。用Heroku托管一个已经制作好的Django网站

我应该遵循哪些步骤才能让我的网站启动?只是FYI我正在使用最新的Django dev分支1.8和Python 3.4.1,它是一个个人网站。

这里是我的settings.py文件

""" 
Django settings for mysite project. 

For more information on this file, see 
https://docs.djangoproject.com/en/dev/topics/settings/ 

For the full list of settings and their values, see 
https://docs.djangoproject.com/en/dev/ref/settings/ 
""" 

# 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/dev/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = '0r58%!j00w2q1faj*57=d)*fv^=ai#-wgnakj91^--z5f(ohq1' 

# 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', 
) 

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
) 

ROOT_URLCONF = 'mysite.urls' 

WSGI_APPLICATION = 'mysite.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/dev/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 

# Internationalization 
# https://docs.djangoproject.com/en/dev/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/dev/howto/static-files/ 

STATIC_URL = '/static/' 

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(BASE_DIR), "static", "templates"), 
    ) 

if DEBUG: 
    MEDIA_URL = '/media/' 
    STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "static-only") 
    MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "media") 
    STATICFILES_DIRS = (
     os.path.join(os.path.dirname(BASE_DIR), "static", "static"), 
     ) 

回答

0

您需要与所有的依赖关系的requirements.txt,因为Heroku的使用该文件为您提供您所需要的服务。

将postgreSQL加载项添加到您的heroku项目后,heroku会生成一个DATABASE_URL环境变量。你可以根据Heroku的教程解析,在你的settings.py:

# Parse database configuration from $DATABASE_URL 
import dj_database_url 
DATABASES['default'] = dj_database_url.config() 

将在本教程还提供了基本的wsgi.py,你可以使用它。

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

application = Cling(get_wsgi_application()) 

将应用程序提交到您的本地git存储库并将其推送到heroku远程存储库。如果你在控制台上这样做,你会得到关于你的部署的良好反馈。

基本上你需要按照getting started tutorial。跳过虚拟环境的东西只是使生成需求文件更复杂,但它是可能的。

相关问题