Django:静态文件未显示在部署服务器上

时间:2016-10-21 19:44:54

标签: python django

我无法让我的网站正确加载静态文件。

关于静态文件的

settings.py文件如下:

# Static files
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/str8red.com/static/'
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

当我运行以下命令时:

python manage.py collectstatic

我得到以下结果:

1858 static files copied to '/var/www/str8red.com/static'

当我检查目录时,一切似乎都正常工作。

然后我去“https://str8red.com/”在线查看我的网站,并且没有任何css或图像正常工作。我在chrome开发人员模式中看到的示例错误如下:

GET https://str8red.com/static/str8RED.png 404 (Not Found)

使用以下代码抓取文件:

{% load staticfiles %}
<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="{% url 'index' %}">
        <img src="{% static 'str8RED.png' %}" width="97" height="22" alt="str8RED.com" />
      </a>

网址文件:

from django.conf.urls import include, url
from django.contrib import admin
from django.views.static import serve
from dwad import settings

urlpatterns = [
    url(r'', include('meta.urls')),
    url(r'^straightred/', include('straightred.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^chaining/', include('smart_selects.urls')),
    url(r'^tinymce/', include('tinymce.urls')),
    url(r'^accounts/', include('allauth.urls')),
]

# Get Django to serve media files in debug mode.
if settings.DEBUG:
    urlpatterns += [url(r'^resources/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})]

非常感谢任何帮助,非常感谢,Alan。

1 个答案:

答案 0 :(得分:0)

您需要在urls.py中添加静态网址规则,以便在获取任何静态网址时告知Django提供静态文件。

your code:   if (connect(sock,(struct sockaddr *)&server,sizeof(server)<0))
correct:     if (connect(sock,(struct sockaddr *)&server,sizeof(server))<0)
                                                                       ^^^^