【发布时间】:2014-04-26 13:41:47
【问题描述】:
所以基本上我已经使用 apache 和 mod wsgi 在 vps 上部署了我的应用程序。对于我的静态文件,我使用了这样的 {% url %} 模板标签:
<link href="{% static "bootstrap.min.css" %}" rel="stylesheet">
Django 没有加载静态文件,因为它正在创建相对 url,所以我通过
修复了它<link href="/{% static "bootstrap.min.css" %}" rel="stylesheet">
但是现在当我转到 /admin 页面时,它不会加载静态文件,这也是因为相对 url。我该如何解决这个问题?
这是我的 wsgi 模组:
import os
import sys
import site
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/tshirtnation')
sys.path.append('/home/tshirtnation/tshirtnation')
os.environ['DJANGO_SETTINGS_MODULE'] = 'tshirtnation.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
还有我的 apache 配置:
#Listen 80
<VirtualHost *:80>
ServerAdmin marijus.merkevicius@gmail.com
ServerName 5.199.166.109
WSGIDaemonProcess ts threads=25
WSGIProcessGroup ts
Alias /static /home/tshirtnation/staticfiles
WSGIScriptAlias / /home/tshirtnation/index.wsgi
</VirtualHost>
如果您还需要什么,请告诉我。
【问题讨论】:
-
@Dan 这根本不是真的。 mod_wsgi 是文档推荐的一个得到良好支持且稳定的组合。 (您可能正在考虑不支持或不推荐的 mod-python。)
-
@Marijus 您应该从 settings.py 发布相关的 STATIC_* 值。
-
@DanielRoseman 你说得对——删除是为了不让人迷惑
标签: python django apache mod-wsgi django-staticfiles