3

I have recently uploaded my app on EC2 server running Ubuntu, Python 2.7.3, django.VERSION 1.5.1. I have managed to successfully launch it without any CSS/Images or JS. I can view templates and navigate them means template directory settings are working. Looks like I am missing some setting for static/media files. Can anyone please advise?

Content of "cat /etc/apache2/httpd.conf"

WSGIScriptAlias / /home/ubuntu/site/ProjectName/ProjectName/wsgi.py
WSGIPythonPath /home/ubuntu/site/ProjectName

<Directory /home/ubuntu/site/ProjectName/ProjectName>
<Files wsgi.py> 
Order deny,allow
Allow from all
</Files>
</Directory>

Content of settings.py

MEDIA_ROOT = '/var/www/media/'
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/var/www/static/admin/'
STATICFILES_DIRS = (
    '/var/www/static',
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

TEMPLATE_DIRS = ('/var/www/templates',)


**$ ls -ltr /var/www**

total 16
-rw-r--r-- 1 root root 177 Jul 26 20:21 index.html
drwxr-xr-x 3 www-data root 4096 Jul 28 04:20 static
drwxr-xr-x 5 www-data root 4096 Jul 28 04:20 media
drwxr-xr-x 20 www-data root 4096 Jul 28 16:29 templates

Errors in apache2/access.log

[29/Jul/2013:13:41:36 -0500] "GET /static/neatadmin/css/bootstrap.css HTTP/1.1" 404 1798 [29/Jul/2013:13:41:36 -0500] "GET /static/neatadmin/css/jquery.fancybox.css HTTP/1.1" 404 1806 [29/Jul/2013:13:41:36 -0500] "GET /static/neatadmin/js/jquery.js HTTP/1.1" 404 1798 [29/Jul/2013:13:41:36 -0500] "GET /static/neatadmin/js/jquery.metadata.js HTTP/1.1" 404 1804 [29/Jul/2013:13:41:36 -0500] "GET /static/neatadmin/css/login.css HTTP/1.1" 404 1794 [29/Jul/2013:13:41:36 -0500] "GET /static/neatadmin/js/error.js HTTP/1.1" 404 1794

Errors in apache2/error.log (I dont think it's relevant but just FYI)

[Mon Jul 29 13:41:29 2013] [error] /usr/local/lib/python2.7/dist-packages/django/conf/init.py:221: DeprecationWarning: You have no filters defined on the 'mail_admins' logging handler: adding implicit debug-false-only filter. See http://docs.djangoproject.com/en/dev/releases/1.4/#request-exceptions-are-now-always-logged [Mon Jul 29 13:41:29 2013] [error] DeprecationWarning) [Mon Jul 29 13:41:29 2013] [error] [Mon Jul 29 13:41:35 2013] [error] /usr/local/lib/python2.7/dist-packages/django/conf/init.py:221: DeprecationWarning: You have no filters defined on the 'mail_admins' logging handler: adding implicit debug-false-only filter. See http://docs.djangoproject.com/en/dev/releases/1.4/#request-exceptions-are-now-always-logged [Mon Jul 29 13:41:35 2013] [error] DeprecationWarning) [Mon Jul 29 13:41:35 2013] [error]

4

1 回答 1

1

您的设置混淆了STATICFILES_DIRS和的用途STATIC_ROOTSTATICFILES_DIRS保存对您的项目来说是全局的额外静态资源。这反映了TEMPLATE_DIRS设置。此目录将包含在您的源存储库中。

STATIC_ROOT是用于在生产中提供静态文件的收集点。来自所有已安装应用程序的文件,并STATICFILES_DIRS在您运行时复制到此处collectstatic。这不需要为本地开发设置。该目录不会包含在 repo 中,因为它只包含生成的内容。您的网络服务器配置应该有一个别名STATIC_ROOT作为STATIC_URL使用 Apache 的示例,您应该查看文档https://docs.djangoproject.com/en/stable/howto/deployment/wsgi/modwsgi/#serving-files

于 2013-07-29T20:01:13.713 回答