All Projects → twtrubiks → Deploying_Django_To_Heroku_Tutorial

twtrubiks / Deploying_Django_To_Heroku_Tutorial

Licence: other
Deploying a Django App To Heroku Tutorial

Programming Languages

CSS
56736 projects
python
139335 projects - #7 most used programming language
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Deploying Django To Heroku Tutorial

Rocket
Automated software delivery as fast and easy as possible 🚀
Stars: ✭ 217 (+985%)
Mutual labels:  heroku, deploy
Deploying Flask To Heroku
Deploying a Flask App To Heroku Tutorial
Stars: ✭ 81 (+305%)
Mutual labels:  heroku, deploy
heroku
Deploy Prime CMS to Heroku in a single click
Stars: ✭ 16 (-20%)
Mutual labels:  heroku, deploy
heroku-deploy
A simple action to build, push and deploy your dockerized app to your Heroku Application
Stars: ✭ 40 (+100%)
Mutual labels:  heroku, deploy
ror-capstone
Ruby on Rails app to track activities and assign a group to them
Stars: ✭ 15 (-25%)
Mutual labels:  heroku
spring-boot-angular2-starter
Starter application. Spring Boot, Angular 2, TypeScript, Gulp, Gradle, SCSS.
Stars: ✭ 35 (+75%)
Mutual labels:  heroku
tgmusicbot
Telegram bot for downloading audio from YouTube, SoundCloud & MixCloud.
Stars: ✭ 66 (+230%)
Mutual labels:  heroku
DaisyX
“ HOLA HUMANS 👋 I'M DAISYX 2.0 heart „ LATEST VERSION OF DAISYX.. Source Code of @Daisyxbot
Stars: ✭ 44 (+120%)
Mutual labels:  heroku
puma-deploy
capistrano deploy script for puma with nginx
Stars: ✭ 14 (-30%)
Mutual labels:  deploy
repl.deploy
Automatically deploy from GitHub to Replit, lightning fast ⚡️
Stars: ✭ 63 (+215%)
Mutual labels:  deploy
Mega-index-heroku
Mega nz heroku index, Serves mega.nz to http via heroku web. It Alters downloading speed and stability
Stars: ✭ 165 (+725%)
Mutual labels:  heroku
slam-mirrorbot
Aria/qBittorrent Telegram mirror/leech bot.
Stars: ✭ 1,072 (+5260%)
Mutual labels:  heroku
help-me
When there's none to go to. In times of danger or trouble, there is nowhere to seek help from. Help-me comes with an innovative solution to the above problem. It will automatically send notifications to your nearby people and it will be the moral duty of the people to help the person in danger.
Stars: ✭ 20 (+0%)
Mutual labels:  heroku
auto crawler ptt beauty image
Auto Crawler Ptt Beauty Image Use Python Schedule
Stars: ✭ 35 (+75%)
Mutual labels:  heroku
mrbelvedere
NOTE: See the old-master branch for the mrbelvedere codebase that was formerly in use.
Stars: ✭ 17 (-15%)
Mutual labels:  heroku
react-landing-page
A landing page in 5 minutes.
Stars: ✭ 26 (+30%)
Mutual labels:  heroku
heroku-colorscheme
I was tired to never find the perfect colorscheme, so I decided to do my own.
Stars: ✭ 43 (+115%)
Mutual labels:  heroku
milvus-helm
The helm chart to deploy Milvus
Stars: ✭ 37 (+85%)
Mutual labels:  deploy
recurse-community-portfolio
Discover all the things Recursers have built!
Stars: ✭ 13 (-35%)
Mutual labels:  heroku
jt tools
Ruby on Rails Continuous Deployment Ecosystem to maintain Healthy Stable Development
Stars: ✭ 13 (-35%)
Mutual labels:  heroku

Deploying_Django_To_Heroku_Tutorial

Deploying a Django App To Heroku Tutorial

後端有一個自動爬蟲的程式去抓圖片,可參考 auto_crawler_ptt_beauty_image

本專案將教大家如何將自己的 Django 佈署到 Heroku

Heroku 免費版本

  • 可以創造 5個 app。
  • 24小時一定要休息6小時的規定。
  • 支援很多種程式語言。
  • 有SSL ( https ) 。

更多說明請參考 Heroku

詳細的步驟可參考 Deploying-Flask-To-Heroku

下面將只介紹佈署 Django 要注意的步驟。

教學

我的 project_name 為 ptt_beauty_images

設定 Procfile

web: gunicorn ptt_beauty_images.wsgi

更多說明請參考

https://devcenter.heroku.com/articles/django-app-configuration#the-basics

設定 ALLOWED_HOSTS

settings.py

ALLOWED_HOSTS = ['*']

設定 Static assets and file serving

settings.py

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

更多說明請參考 https://devcenter.heroku.com/articles/django-app-configuration#static-assets-and-file-serving

設定 Whitenoise

settings.py

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

wsgi.py

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

更多說明請參考 https://devcenter.heroku.com/articles/django-app-configuration#whitenoise

設定 Collectstatic

Disabling Collectstatic

heroku config:set DISABLE_COLLECTSTATIC=1

更多說明請參考

https://devcenter.heroku.com/articles/django-assets#collectstatic-during-builds

設定 DATABASE

settings.py

我使用 Heroku Postgres ,

詳細教學可參考 如何在 heroku 上使用 database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DATABASE_NAME'),
        'USER': os.environ.get('DATABASE_USER'),
        'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
        'HOST': os.environ.get('DATABASE_HOST'),
        'PORT': os.environ.get('DATABASE_PORT'),
    }
}

請在自己 Heroku 的 Config Variables 設定 DATABASE 連線字串

Django multiple-databases

順便介紹在 Django 中的 multiple-databases,

使用方法, 將 settings.py 裡的 DATABASES 修改成如下

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DATABASE_NAME'),
        'USER': os.environ.get('DATABASE_USER'),
        'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
        'HOST': os.environ.get('DATABASE_HOST'),
        'PORT': os.environ.get('DATABASE_PORT'),
    },
    'db2': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DATABASE_NAME_2'),
        'USER': os.environ.get('DATABASE_USER_2'),
        'PASSWORD': os.environ.get('DATABASE_PASSWORD_2'),
        'HOST': os.environ.get('DATABASE_HOST_2'),
        'PORT': os.environ.get('DATABASE_PORT_2'),
    }
}

這樣就代表你有兩個 DATABASES,更多資料可參考 Django multi-db

如果要指定 DATABASES 也非常容易,

假設我今天要用 'default' 這個 DB ,可以寫這樣

Image.objects.using('default').all()

假設我今天要用 'db2' 這個 DB,可以寫這樣

Image.objects.using('db2').all()

有沒有發現,其實就是 using('database name') 這樣,非常簡單

更多資料可參考 Django manually-selecting-a-database

執行環境

  • Python 3.6.0

Reference

Donation

文章都是我自己研究內化後原創,如果有幫助到您,也想鼓勵我的話,歡迎請我喝一杯咖啡😆

alt tag

贊助者付款

License

MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].