【发布时间】:2016-12-10 18:50:30
【问题描述】:
我已尝试遵循其他堆栈溢出帖子中有关在生产中提供 Django 静态文件的解决方案,但我无法让它们工作。我的静态文件位于我的 django app 文件夹(联盟)中。
我的 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 文件也没有正确加载...
当我在 chrome 上检查源文件并单击 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 webmaster@localhost
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 %} 标签。
标签: django apache python-2.7 mod-wsgi