Python 无法获取静态文件以使管理员正常工作

Python 无法获取静态文件以使管理员正常工作,python,django,apache,mod-wsgi,Python,Django,Apache,Mod Wsgi,正如标题所述,所有404都带有: Page not found (404) Request Method: GET Request URL: http://localhost/static/admin/css/base.css Using the URLconf defined in djcms.urls, Django tried these URL patterns, in this order: ^admin/ The current URL, static/a

正如标题所述,所有404都带有:

Page not found (404)
Request Method:     GET
Request URL:    http://localhost/static/admin/css/base.css

Using the URLconf defined in djcms.urls, Django tried these URL patterns, in this order:

    ^admin/

The current URL, static/admin/css/base.css, didn't match any of these.
基本上,我只是按照DjangoProject.com上的教程来做,所以除了Django本身,这里没有什么复杂的事情

我的文件夹结构如下所示:

root@jerkstore:/var/www/djcms# ls -lsa
total 36
4 drwxrwxr-x  6 myusername myusername 4096 Jul 11 11:49 .
4 drwxr-xr-x 10 myusername www-data  4096 Jul 10 16:34 ..
4 drwxrwxr-x  5 myusername myusername 4096 Jul 11 11:40 admin
4 drwxrwxr-x  2 myusername myusername 4096 Jul 11 15:38 djcms
4 -rwxr-xr-x  1 myusername myusername  248 Jul 10 16:34 manage.py
4 drwxrwxr-x  2 myusername myusername 4096 Jul 11 10:53 polls
4 -rw-rw-r--  1 myusername myusername  415 Jul 11 10:26 .project
4 -rw-rw-r--  1 myusername myusername  577 Jul 11 10:26 .pydevproject
4 drwxrwxr-x  2 myusername myusername 4096 Jul 11 11:43 static

root@jerkstore:/var/www/djcms# ls -lsa static/
total 12
4 drwxrwxr-x 2 myusername myusername 4096 Jul 11 11:43 .
4 drwxrwxr-x 6 myusername myusername 4096 Jul 11 11:49 ..
4 lrwxrwxrwx 1 myusername myusername   73 Jul 11 11:43 admin -> /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin/

root@jerkstore:/var/www/djcms# ls -lsa static/admin/
total 20
4 drwxr-sr-x 5 root staff 4096 Jul 10 16:33 .
4 drwxr-sr-x 3 root staff 4096 Jul 10 16:33 ..
4 drwxr-sr-x 2 root staff 4096 Jul 10 16:33 css
4 drwxr-sr-x 3 root staff 4096 Jul 10 16:33 img
4 drwxr-sr-x 3 root staff 4096 Jul 10 16:33 js
注意:在Apache中启用了FollowSymLinks

settings.py的相关部分如下所示:

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = '/var/www/djcms/static'

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    #'/var/www/djcms/static',
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

ADMIN_MEDIA_PREFIX = '/static/admin/'

我在settings.py中尝试了几种不同的静态变量排列,但到目前为止没有任何效果,我也没有搜索到任何其他内容。

看起来对
admin
应用程序静态文件的请求正在冲击Django应用程序。我假设您的URL定义正确,但值得使用Django静态文件配置重新检查

如图所示:

提供文件 除了这些配置步骤之外,您还需要实际提供静态文件

在开发过程中,如果您使用并设置为
True
(请参阅),这将自动完成

这种方法效率极低,可能不安全,因此不适合生产

有关在生产环境中为静态文件提供服务的正确策略,请参阅

这意味着,您需要设置web服务器(例如Apache)以在Django之外提供静态文件(因此对该URL的请求甚至不应该到达Django应用程序)


还要确保您已调用。

Yep,将所有这些添加到Apache的主机配置中即可。谢谢调试设置为True是我的问题。谢谢