2017-07-29 123 views
0

服務器在本地服務器上的Ubuntu 16.04.2 x64上啓動,所有的工作設置都與只在這裏啓動的相同,無法找到它們!Django staticfiles 404部署到數字海洋

設置

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

urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r'^chart/', include("charts.urls", namespace='charts')), 
    url(r'^comments/', include("comments.urls", namespace='comments')), 
    url(r'^im/', include("messenger.urls", namespace='im')), 
    url(r'^accounts/', include("accounts.urls", namespace='accounts')), 
    url(r'^series/', include("serials.urls", namespace='series')), 
    url(r'^', include("serials.urls", namespace='homeview')), 




]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 

在本地服務器上的一切

STATIC_URL = '/static/' 

STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, "static"), 
    #'/var/www/static/', 

] 

STATIC_ROOT  = os.path.join(BASE_DIR, "static_cdn") 
MEDIA_URL  = "/media/" 
MEDIA_ROOT  = os.path.join(BASE_DIR, "media_cdn") 

網址的偉大工程,但是當我在現場staticfiles啓動它沒有找到

> [29/Jul/2017 07:54:38] "GET /static/css/bootstrap.min.css HTTP/1.1" 
> 404 102 [29/Jul/2017 07:54:38] "GET /static/js/bootstrap.min.js 
> HTTP/1.1" 404 100 [29/Jul/2017 07:54:38] "GET 
> /static/min_css/base.min.css HTTP/1.1" 404 101 [29/Jul/2017 07:54:38] 
> "GET /static/js/Chart.min.js HTTP/1.1" 404 96 [29/Jul/2017 07:54:38] 
> "GET /static/js/smooth-scroll.js HTTP/1.1" 404 100 [29/Jul/2017 
> 07:54:38] "GET /static/js/script.js HTTP/1.1" 404 93 [29/Jul/2017 
> 07:54:39] "GET /static/js/bootstrap.min.js HTTP/1.1" 404 100 
> [29/Jul/2017 07:54:39] "GET /static/js/Chart.min.js HTTP/1.1" 404 96 
> [29/Jul/2017 07:54:39] "GET /static/js/smooth-scroll.js HTTP/1.1" 404 
> 100 [29/Jul/2017 07:54:39] "GET /static/js/script.js HTTP/1.1" 404 93 

回答

0

您必須爲此部署靜態文件! 在你的設置中替換你的staticfiles常量,一切都會很棒!

STATIC_URL = '/static/' 

STATICFILES_DIRS = [ 

    os.path.join(BASE_DIR, "static") 

] 

MEDIA_URL = '/media/' 

STATIC_ROOT = '../static/' 

MEDIA_ROOT = '../media/' 

如果它不工作使用完整路徑! 是這樣的:

STATIC_ROOT = '/var/www/static/', 
1

聽起來像是你有沒有運行python manage.py collectstatic。這會將你的靜態文件複製到正確的位置。

如果這樣不起作用,請檢查您的Web服務器配置。

+0

如何配置服務器? – InvictusManeoBart

+0

你使用什麼網絡服務器? Nginx還是Apache? –

+0

我使用Nginx服務器 – InvictusManeoBart

相關問題