在部署django應用程序時。我遇到了靜態文件的問題。我有靜態目錄中的JS和CSS文件。但瀏覽器無法找到這些文件。我在本地機器上擁有與服務器操作系統相同的文件和設置,並且已經在本地工作。儘管它具有相同的設置,但我正在粘貼下面的靜態目錄和文件設置。在上面的代碼中在django 1.4中找不到靜態文件
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(ROOT_PATH,'static')
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS =(
os.path.join(ROOT_PATH,'static'),
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
這裏的根路徑定義之前即:
import os
#from django.contrib.sites.models import Site
ROOT_PATH = os.path.dirname(__file__)
我使用的mod_wsgi與Apache2的,在我的理解,應該找到文件,它加載時/ somefoldername然後瀏覽器應該去那個目錄但沒有得到問題的地方。瞭解環境和wsgi設置e.t.c.我在這裏下面是我發佈我的wsgi文件的詳細信息和它的工作方式的問題:500 server error on django site after shifting to server
我很多時候遇到問題,而找到應用程序和其他模板和模塊e.t.c.即使在服務器上的syncdb命令中,對於模板我追加了根路徑,它開始工作,也在wsgi文件中添加了項目路徑,但仍然沒有解決靜態文件問題。請告訴我們您是否對我在做什麼錯誤或者這裏有什麼問題有所瞭解。
在此先感謝球員
其中存儲在Apache服務器上的靜態文件嗎? 'MEDIA_ROOT'和'MEDIA_URL'應該指向它。 –
這聽起來像你需要設置一個別名從'/靜態/'到你的apache站點配置中的靜態目錄。 – drewman
@drewman如何在我的apache站點配置中將別名設置爲/ static /? – Hafiz