Skip to content

Instantly share code, notes, and snippets.

@andy23512
Last active March 8, 2019 11:56
Show Gist options
  • Save andy23512/98ee08f19b38e62ebb9f1260ac25be8c to your computer and use it in GitHub Desktop.
Save andy23512/98ee08f19b38e62ebb9f1260ac25be8c to your computer and use it in GitHub Desktop.

所以想請問有經驗的人是用哪一套在local端開發的呢?

local端web server應該用django附的dev server就夠了(./manage.py runserver)
DBMS的部分如果沒有用到特殊field(JSONField那類)的話應該就用SQLite就足夠了

資料如何管控,例如local 端是去存取另外一個資料庫嗎? 如果是另一個資料庫,那deploymenet的時候又要改來改去了。

  1. 你可以分成devlopment用的和production用的settings.py https://gist.github.com/andy23512/6a5c6488c2576be1bf1b659a45c380e5 這個是我為了跑自動化測試而另外寫出的test_settings.py 這樣只要在執行時附加--settings=web.test_settings就可以使用不同的settings 或者用個if判斷目前debug狀態然後去決定django的database設定
if DEBUG: # development
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3', # use SQLite
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }
else: # production
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql', # use PostgreSQL
            # other database settings (host, name, user, ...)
        }
    }
  1. 另外也可以弄一個config.ini或.env檔,來集中管理設定(DEBUG設定, 資料庫連線所需的設定),之後再在settings裡面讀那個設定檔進來,這樣就不用改一堆地方 https://stackoverflow.com/questions/10664244/django-how-to-manage-development-and-production-settings 這篇也有提供各種不同的設定方式

又media下的圖片,未來圖片越來越多,server端與local端都要maintain一樣的圖?

這要看你的應用,我是不認為一般情況開發過程中還需要用到production(server端)的所有圖 如果真的需要的話那理論上就得maintain,或者想其他方式同步server端與local端的圖檔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment