2014-07-19 72 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。跳過虛擬環境的東西只是使生成需求文件更復雜,但它是可能的。

相關問題