在部署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