2026年2月19日 星期四

[Django 6.0] 把尚虎雲生產端佈署到Render平台

1.下載尚虎雲生產端的軟體

載點:https://github.com/shanghuyun-team/Shanghuyun-Production-side/releases

2.解開後的目錄


3.增加render.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
databases:
  - name: Shanghuyundb          # 資料庫服務名稱(可自訂)
    plan: free              # free / starter 等,免費版夠用
    databaseName: Shanghuyun    # 資料庫名稱
    user: Shanghuyun            # 使用者名稱(Render 會自動產生密碼)

services:
  - type: web
    name: Shanghuyun-Production-Side           # Web Service 名稱
    env: python             # Python 環境
    plan: free              # 免費方案
    region: singapore       # 建議選離台灣近的(如 singapore 或 oregon),跟資料庫同區域避免延遲
    buildCommand: pip install -r requirements.txt && python manage.py collectstatic --noinput
    startCommand: gunicorn core.wsgi:application --bind 0.0.0.0:$PORT
    # 如果你的專案資料夾是 Shanghuyun-Production-Side/core(內層),startCommand 改成:gunicorn Shanghuyun-Production-Side.wsgi:application ...

    envVars:
      - key: PYTHON_VERSION
        value: 3.14.1           # 或你的 Python 版本
      - key: SECRET_KEY
        generateValue: true   # Render 自動產生安全的 SECRET_KEY
      - key: DEBUG
        value: "False"
      - key: DATABASE_URL
        fromDatabase:
          name: mysitedb      # 對應上面的資料庫 name
          property: connectionString  # 自動注入 postgresql://... 格式
      - key: ALLOWED_HOSTS
        value: "*"            # 測試用,之後改成你的域名

4.在Github建Rep
Shanghuyun-Production-side

5.把軟體上傳到Github
  • 如果還沒 repo:
git init
git add .
git commit -m "Initial commit"
  • 建立 GitHub repo(private 或 public 都行)
  • push:
git remote add origin https://github.com/你的帳號/你的專案.git
git branch -M main
git push -u origin main

6. 建立新的藍圖

https://dashboard.render.com/blueprints




7.在Start Command中填入:
gunicorn core.wsgi:application --bind 0.0.0.0:$PORT

按下佈署鍵

8.佈署完成後,按下連結打開

沒有留言:

張貼留言