issue in loading static contents in django1.3+mod_wsgi+apache2

﹥>﹥吖頭↗ 提交于 2020-01-16 19:23:11

问题


I am facing problem with static files(Django1.3) when tried to deploy it in my local apache server(apache2+mod_wsgi), the problem only for the static contents other parts ok[its worked in the devlopment server].

My project now in a folder 'testcloud' in Ubandu Desktop,My project name is DjangoApis,Following is my project structure: Desktop->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/sites/enabled/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/

errorlog of 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"
.........................

Note I used collectstatic command. Please help me to solve the issue,Thanks in advace.


回答1:


Look closely, Apache tries to load files from /home/jisson/Desktop/testcloud.aws/DjangoApis/staticjs, not /home/jisson/Desktop/testcloud.aws/DjangoApis/static/js like you wanted.

If files are correctly collected by collectstatic command (they appear in STATIC_ROOT directory after running that command), then problem is not in Django side, but rather in Apache, so you should check your Apache configuration files.



来源:https://stackoverflow.com/questions/8456083/issue-in-loading-static-contents-in-django1-3mod-wsgiapache2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!