我已經嘗試了其他堆棧溢出文章中關於在生產中服務Django靜態文件的解決方案,但我無法讓他們工作。我的靜態文件位於我的django應用程序文件夾(聯盟)內。服務靜態文件django 1.9生產錯誤
我的CSS文件沒有正確加載;我得到了在控制檯下面的錯誤在chrome:
Resource interpreted as Stylesheet but transferred with MIME type text/html
Uncaught SyntaxError: Unexpected token !
profile:5 Uncaught SyntaxError: Unexpected token !
我認爲,CSS文件被解釋爲HTML文件?我不認爲JavaScript文件正在正確加載...
當我檢查鉻上的源文件,並點擊鏈接到CSS文件,他們不工作。所以我猜測,到CSS文件的鏈接不起作用?
的聯繫和腳本加載CSS和JavaScript文件是:
<head>
<!-- Latest compiled and minified CSS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="{% static 'league/css/bootstrap-theme.css' %}">
<link rel="stylesheet" href="{% static 'league/css/bootstrap-theme.min.css' %}">
<link rel="stylesheet" href="{% static 'league/css/bootstrap.css' %}">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script type="text/javascript" src="{% static 'league/js/bootstrap.min.js' %}"></script>
<script type="text/javascript" src="{% static 'league/js/npm.js' %}"></script>
<!-- jQuery library -->
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" href="{% static 'league/css/f-style.css' %}">
</head>
我是在我的settings.py文件中的相關文件如下:
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
STATIC_URL = '/league/static/'
SITE_ID = 1
STATIC_ROOT = BASE_DIR + '/league/static/'
配置文件在我apache服務器如下:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html
Alias /static /home/ubunu/project/league/static
<Directory /home/ubuntu/project/league/static>
Require all granted
</Directory>
<Directory /home/ubuntu/project/fantasy>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess project python-path=/home/ubuntu/project:/home/ubuntu/project/myprojectenv/lib/python2.7/$
WSGIProcessGroup project
WSGIScriptAlias//home/ubuntu/project/fantasy/wsgi.py
</VirtualHost>
謝謝!
沒有你試圖重新啓動服務器的服務器。而在你的模板中,你還沒有使用{%load staticfiles%}標籤。 –