我的生产中的静态文件出现404错误。奇怪的是,django-rest-framework和admin将静态文件放在我设置的正确目录中。我正在使用Digitalocean来托管我的网站。
Directorys:
-django_project
- django_project
- templates
- media
- static
- apps etc
settings.py:
SATICFILES_DIRS = (
'/home/django/django_project/static/',
)
STATIC_URL = '/static/'
STATIC_ROOT = '/home/django/django_project/static/'
urls.py:
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
base.html文件:
{% load static %}
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Application</title>
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
</head>
答案 0 :(得分:0)
尝试将您的网址更改为:
if settings.DEBUG:
urlpatterns += patterns('',) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += patterns('',) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
您需要包含初始网址格式。