当我尝试在生产中部署它们时,我的所有静态文件都出现了404错误
A live page of the site is available here。在Chromes Console或Firebug中检查页面将显示以下问题。
我无法理解为什么会发生这种情况,因为上面的404错误与我的CSS文件的位置完全匹配
/var/www/bias_experiment/static/survey/css/bootstrap.css
我试图解决这个问题几天但是无法解决这个问题。
以下是我的所有设置。我认为最好包括可能有用的所有内容以及我采取的所有步骤。道歉的长度。
settings.py
DEBUG = True
STATIC_ROOT = '/var/www/bias_experiment/static/'
STATIC_URL = '/bias_experiment/static/'
STATICFILES_DIRS = (
'/var/www/bias_experiment/src/survey/static/survey/css',
'/var/www/bias_experiment/src/survey/static/survey/js',
'/var/www/bias_experiment/src/survey/static/survey/fonts',
)
我正在使用STATIC_URL = '/bias_experiment/static/'
,因为我使用的是通过http://phaedrus.scss.tcd.ie/bias_experiment/
如果我使用STATIC_URL = '/static/'
,我会收到403禁止错误。
slide_test.html
{% load staticfiles %}
<!-- THESE WORK LOCALY BUT DO NOT WORK ON THE SERVER -->
<link rel = "stylesheet" href ="{% static "survey/css/bootstrap.min.css" %}" >
<link rel = "stylesheet" href ="{% static "survey/css/bootstrap.css" %}">
<link rel="stylesheet" href ="{% static "survey/css/jquery-ui.css" %}">
<link rel="stylesheet" href ="{% static "survey/css/slider.css" %}">
<script src="{% static "survey/js/jquery.min.js" %}"></script>
<script src="{% static "survey/js/jquery-ui.js" %}"></script>
<script src="{% static "survey/js/slider.js" %}"></script>
我的默认apache文件 / etc / apache2 / sites-available / default
Alias /static/ /var/www/bias_experiment/static/
<Directory /var/www/bias_experiment/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /bias_experiment /var/www/bias_experiment/src/bias_experiment/index.wsgi
<Directory /var/www/bias_experiment/src/bias_experiment>
<Files index.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>
...
standard apache default settings here
...
</VirtualHost>
根据DjangoProject 1.6文档(我正在使用Apache / 2.2.22(Ubuntu))
如果您使用的是早于2.4的Apache版本,请替换Require 所有授予所有允许,并添加行拒绝,允许 在它之上。
我已重新启动并重新加载Apache
sudo service apache2 restart
sudo service apache2 reload
运行collectstatic
没问题
我已使用以下命令
将所收集文件的所有权设置为www-data:www-datasudo chown -R www-data:www-data /var/www/bias_experiment/static/
我甚至已经禁用并重新启用了apache2中的默认文件
sudo a2dissite default
sudo a2ensite default
然后重新启动
sudo service apache2 restart
sudo service apache2 reload
我正在使用
其中一个CSS文件的绝对路径是http://phaedrus.scss.tcd.ie/bias_experiment/static/survey/css/bootstrap.min,以防它有用。
但是我似乎无法得到test deployment page I am working to show its CSS or JS。 我真的不确定我要离开的是什么。如果有人可以提出任何建议,将非常感激。
我几天前向我提出了一个类似的问题我已经删除了,因为我犯了太多错误,而且缺乏细节和明确的问题。
由于
答案 0 :(得分:2)
有关:
STATIC_URL = '/bias_experiment/static/'
在Django设置模块中,你应该使用:
Alias /bias_experiment/static/ /var/www/bias_experiment/static/
在Apache配置中。
答案 1 :(得分:0)
请勿在{{1}}中使用STATIC_ROOT
。它们不应该是一样的。因为当您运行STATICFILES_DIRS
进行部署时,它们将被覆盖,并且还会查看此页面Managing static files (CSS, images)
#settings.py
STATIC_URL ='/ static /'
#STATIC_ROOT = os.path.join(BASE_DIR,'static')
python manage.py collectstatic
这个WSGI代码适合我
# Introduce templates
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'somewhereelse'),
os.path.join(BASE_DIR, 'templates')]
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'dajaxice.finders.DajaxiceFinder',
)