【问题标题】:Django finding static file (1.5) ERROR 404 1649Django 查找静态文件 (1.5) ERROR 404 1649
【发布时间】:2013-10-28 17:19:27
【问题描述】:

我真的很难设置我的 Django 站点(本地)。我已经阅读了其他问题和答案,但我无法弄清楚。

[20/Oct/2013 03:56:33] "GET /rides/ HTTP/1.1" 200 230
[20/Oct/2013 03:56:33] "GET /static/rides/style.css HTTP/1.1" 404 1649

静态.css

    li a {
    color: green;
}

index.html

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'rides/style.css' %}" />

settings.py

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/

STATIC_URL = '/static/'

我的 style.css 位于

/Users/Marcus/Sites/Django/groupride/static/rides/style.css

有谁知道我该如何解决这个问题?

谢谢

【问题讨论】:

  • 解决方案:STATICFILES_DIRS = (# 你的应用程序的位置,不应该是公共网络可访问的 '/Users/Marcus/Sites/Django/groupride/static', )

标签: python css django web-applications


【解决方案1】:

您想使用开发服务器来提供静态服务,因此您需要在 urls.py 中添加以下内容:

(r'^static/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'document_root': '/path/to/your/static/'}),

不要在生产环境中使用它。

【讨论】:

    猜你喜欢
    • 2013-08-03
    • 2019-01-12
    • 2021-01-25
    • 2017-09-13
    • 2016-09-24
    • 1970-01-01
    • 2012-09-30
    • 2020-10-17
    相关资源
    最近更新 更多