Re: [問題] 想請問如何在django設定URL轉到某特定資料夾
※ 引述《blackie1019 (blackie)》之銘言:
幫他抓完藥就消失了-_-為了以後朋友查閱方便我把當時的的答案說一下。
他的問題在於Django在settings.py中DEBUG=True時會自動供應其他的靜態檔案
(圖片/JS/CSS...etc),但文件中有提到用Django/WSGI供應靜態檔案效能很糟糕,實務上
會用不同的HTTP Server專門去供應這些靜態檔案,所以在DEBUG=False時,必須先使用
Django manage.py的collectstatic放到檔案系統內指定的位置再由HTTP Server去作
首先必須在settings.py指定collectstatic要收到的位置
(settings.py)
STATIC_ROOT = '/home/django_user/project/static'
然後使用collectstatic讓Django把檔案集中到指定位置
> python manage.py collectstatic
最後設定你的HTTP Server讓她提供static檔案
(這邊用Apache2作例子: /etc/apache2/httpd.conf)
Alias /static/ /path/to/mysite.com/static/
參照:
https://docs.djangoproject.com/en/1.5/howto/static-files/
https://docs.djangoproject.com/en/1.5/ref/contrib/staticfiles/#module-django.contrib.staticfiles
https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.223.3.248
推
07/30 23:26, , 1F
07/30 23:26, 1F
→
07/30 23:30, , 2F
07/30 23:30, 2F
→
07/30 23:56, , 3F
07/30 23:56, 3F
※ 編輯: doomleika 來自: 42.79.167.203 (07/31 00:23)
※ 編輯: doomleika 來自: 42.79.167.203 (07/31 00:32)
※ 編輯: doomleika 來自: 42.79.167.203 (07/31 01:47)
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章