django部署网站没有加载静态

时间:2022-09-16 19:18:37

Perhaps I have miss understood something? I've deployed a site on my Amazon ec2 server, and it loads the page, but not the static. I've placed the "site_media" directory under the "www" directory like so: www/site_media/static etc. And when I inspect an image element on the site, it;s URL seams to point to the right direction as http://mysite.com/site_media/static/img/logo_text.jpg (mysite is replaced with my site url) but when I visit the page I get a 404 page not found. Since I have debug still turned on right now, I get a list of available URLS, the one pertaining to static is ^site\_media\/media\/(?P<path>.*)$ But then it says The current URL, site_media/static/img/logo_text.jpg, didn't match any of these.

也许我想念一些东西?我在我的Amazon ec2服务器上部署了一个站点,它加载了页面,但没有加载静态。我已将“site_media”目录放在“www”目录下,如下所示:www / site_media / static等。当我检查网站上的图像元素时,它的URL接缝指向正确的方向为http: //mysite.com/site_media/static/img/logo_text.jpg(mysite替换为我的网站网址)但是当我访问该网页时,我找不到404页面。由于我现在调试仍然打开,我得到一个可用的URL列表,一个属于静态的是^ site \ _media \ / media \ /(?P 。*)$但是它说当前的URL ,site_media / static / img / logo_text.jpg,与这些中的任何一个都不匹配。

Here is the static in my settings.py file:

这是我的settings.py文件中的静态:

STATIC_ROOT = os.path.join(PACKAGE_ROOT, "site_media", "static")


STATIC_URL = "http://mysite.com/site_media/"


STATICFILES_DIRS = [
    os.path.join(PACKAGE_ROOT, "static"),

]


STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
]

And here is how the static is added into my main urls.py file:

以下是静态添加到我的主urls.py文件中的方法:

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Let me know if you need any additional info!

如果您需要任何其他信息,请告诉我们!

1 个解决方案

#1


1  

Shouldn't you be using STATIC_URL and STATIC_ROOT in your urlpattern rather than MEDIA_URL and MEDIA_ROOT?

您不应该在urlpattern而不是MEDIA_URL和MEDIA_ROOT中使用STATIC_URL和STATIC_ROOT吗?

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

#1


1  

Shouldn't you be using STATIC_URL and STATIC_ROOT in your urlpattern rather than MEDIA_URL and MEDIA_ROOT?

您不应该在urlpattern而不是MEDIA_URL和MEDIA_ROOT中使用STATIC_URL和STATIC_ROOT吗?

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)