我试图在我的本地apache服务器(apache2 + mod_wsgi)中部署静态文件时遇到问题(Django1.3),仅针对静态内容的 问题 其他部分确定[它在开发服务器中工作]。
我的项目现在位于Ubandu Desktop的一个文件夹'testcloud',我的项目 name是DjangoApis,以下是我的项目结构: 桌面 - > testcloud:
DjangoApis
...
mywebapp
static
templates
templatetags
urls.py
views.py
myapis
.....
Settings.py
STATIC_ROOT = '/home/jisson/Desktop/testcloud.aws/DjangoApis/
teststaticfiles/'
STATIC_URL = '/static/'
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.media",
"django.core.context_processors.static",
)
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__),'templates').replace('\
\','/'),
)
INSTALLED_APPS = (
'DjangoApis.mywebapp',
'DjangoApis.myapis',
)
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__),'static').replace('\
\','/'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
的/ etc / apache2的/位点/启用/ DjangoApis:
Alias /favicon.ico /home/jisson/Desktop/testcloud.aws/DjangoApis/ static/favicon.ico AliasMatch ^/([^/]*\.css) /home/jisson/Desktop/testcloud.aws/ DjangoApis/static/styles/$1 Alias /static/ /home/jisson/Desktop/testcloud.aws/DjangoApis/static/ <Directory /home/jisson/Desktop/testcloud.aws/DjangoApis/static> Order deny,allow Allow from all </Directory> WSGIScriptAlias / /home/jisson/Desktop/testcloud.aws/DjangoApis/ django.wsgi
apache errorlog:
tail /var/log/apache2/error.log
[Sat Dec 10 03:16:36 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticjs,
referer: http://test.webapp/
[Sat Dec 10 03:16:36 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticjs,
referer: http://test.webapp/
[Sat Dec 10 03:16:36 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticjs,
referer: http://test.webapp/
[Sat Dec 10 03:16:36 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticjs,
referer: http://test.testapp/
[Sat Dec 10 03:16:45 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticimages,
referer: http://test.webapp/
[Sat Dec 10 03:16:45 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticimages,
referer: http://test.webapp/
[Sat Dec 10 03:16:45 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticimages,
referer: http://test.webapp/
[Sat Dec 10 03:16:45 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticimages,
referer: http://test.webapp/
[Sat Dec 10 03:16:45 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticimages,
referer: http://test.webapp/
[Sat Dec 10 03:16:45 2011] [error] [client 127.0.0.1] File does not
exist: /home/jisson/Desktop/testcloud.aws/DjangoApis/staticimages,
referer: http://testwebapp/
firebug的错误日志:
test.webapp (line 62)
"NetworkError: 404 NOT FOUND - http://test.webapp/css/styles/index.css/"
/css/s...ex.css/
"NetworkError: 404 Not Found - http://test.webapp/static/images/logo.jpg"
logo.jpg
"NetworkError: 404 Not Found - http://test.webapp/static/images/line.jpg"
line.jpg
"NetworkError: 404 Not Found - http://test.webapp/static/images/banner_phone.jpg"
.........................
注意我使用了collectstatic命令。 请帮我解决这个问题,谢谢你。
答案 0 :(得分:1)
仔细观察,Apache尝试从/home/jisson/Desktop/testcloud.aws/DjangoApis/staticjs
加载文件,而不是/home/jisson/Desktop/testcloud.aws/DjangoApis/static/js
加载文件。
如果文件被collectstatic命令正确收集(它们在运行该命令后出现在STATIC_ROOT目录中),则问题不在Django方面,而是在Apache中,因此您应该检查Apache配置文件。