静态文件存在于本地计算机上的firstproject / music / static /文件夹中。
在EB环境中,静态文件的路径是: /家庭/ Ubuntu的/ firstproject /音乐/静态/`
在settings.py中,我写道:
{ group: "asdf", password: "asdf, "username: "asdf" }
在urls.py中:
STATIC_ROOT = '/home/ubuntu/moodyteens/music/static/'
STATIC_URL = '/music/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # it is the original path where file is being saved.
MEDIA_URL = '/media/' # it is the reference given to the path.
我正在使用base.html中的静态文件:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^music/', include('music.urls')),
url(r'^', include('music.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
如何设置静态文件的相对路径?为什么静态文件在localhost上完美运行,但在AWS EB环境中却没有?
我还运行了' python manage.py collectstatic'在服务器端。