需要查看自己的settings文件確保有一下內(nèi)容
import os PROJECT_ROOT = os.path.dirname(__file__) DEBUG = True STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(PROJECT_ROOT, 'static'), ) STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', )
如果項(xiàng)目是使用eclipse啟動(dòng)的django工程 settings文件中的DEBUG 值要等于True 靜態(tài)文件才能訪問?這一點(diǎn)不太明白
如果需要部署到web站點(diǎn)上需要在apache中配置靜態(tài)文件映射
<VirtualHost *:80> ServerName www.mydjangosite.com ServerAlias mydjangosite.com ServerAdmin fake@mydjangosite.com DocumentRoot /path/to/mydjangosite <Directory /path/to/mydjangosite> Options FollowSymLinks AllowOverride None Order allow,deny allow from all </Directory> Alias /static/ /path/to/mydjangosite/static/ <Directory /path/to/mydjangosite/static> Order allow,deny allow from all </Directory> # The following installs the Django WSGI app WSGIDaemonProcess www.mydjangosite.com processes=2 threads=15 display-name=%{GROUP} WSGIProcessGroup www.mydjangosite.com WSGIScriptAlias / /path/to/mydjangosite/wsgi.py </VirtualHost>
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
更多python django 訪問靜態(tài)文件出現(xiàn)404或500錯(cuò)誤相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com