gpt4 book ai didi

python - 静态文件上的 Django 1.5 GET 404

转载 作者:太空狗 更新时间:2023-10-30 00:33:02 24 4
gpt4 key购买 nike

我需要一点帮助,我一直在寻找没有结果的解决方案。

这是我的设置:设置.py:

STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"

STATIC_URL = '/static/'

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

STATICFILES_DIRS = (
PROJECT_ROOT + '/static/'
)

已安装的应用:

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin', . . .

以 DEBUG = TRUE 运行:

August 01, 2013 - 16:59:44
Django version 1.5.1, using settings 'settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[01/Aug/2013 16:59:50] "GET / HTTP/1.1" 200 6161
[01/Aug/2013 16:59:50] "GET /static/media/css/jquery-ui/ui-lightness/jquery-ui- 1.10.3.custom.min.css HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/css/bootstrap/bootstrap.css HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/css/bootstrap/bootstrap-responsive.min.css HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/css/styles.css HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/js/jquery/jquery-1.9.1.min.js HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/js/bootstrap/bootstrap.min.js HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/js/jquery-ui/jquery-ui-1.10.3.custom.min.js HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/js/messages.js HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/js/validate/jquery.validate.min.js HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/images/FERREMOLQUES2.png HTTP/1.1" 404 5904
[01/Aug/2013 16:59:50] "GET /static/media/js/dynamic-style.js HTTP/1.1" 404 5904

特别值得一提的是,我在 VIRTUALENV 中运行 Django 1.5.1 和 Python 2.7.5。不知道是不是这个配置导致的问题

任何帮助将不胜感激

谢谢。

编辑:当我关闭 VIRTUALENV 并安装正确版本的 Django 和项目的依赖项时,我的项目运行良好,没有任何问题。 . .静态显示应有的样子

最佳答案

你确定你的 STATICFILE_DIRS 是正确的吗?如果您现在的设置是这样的,static 文件夹应该与 settings.py 处于同一级别。

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) # it means settings.py is in PROJECT_ROOT?
STATICFILES_DIRS = (
PROJECT_ROOT + '/static/', # <= don't forget a comma here
)

我的普通 settings.py 有点不同:

ROOT_PATH = path.join(path.dirname(__file__), '..')  # up one level from settings.py
STATICFILES_DIRS = (
path.abspath(path.join(ROOT_PATH, 'static')), # static is on root level
)

除此之外,您需要 django.core.context_processors.static 作为上下文处理器:

TEMPLATE_CONTEXT_PROCESSORS = (
# other context processors....
'django.core.context_processors.static',
)

并在 urls.py 中启用 urlpattern:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()

希望对您有所帮助!

关于python - 静态文件上的 Django 1.5 GET 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18005574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com