D
D
DmSS19972022-02-07 13:49:45
Django
DmSS1997, 2022-02-07 13:49:45

Django stops seeing images from static because of the url. How to create url in this case?

On some pages, images from the static/image folder no longer appear on my pages, but at the same time, styles and scripts are also loaded from static without problems, only there was trouble with the pictures.

I was looking for a reason for a long time and accidentally found it. It turns out that if you add '/' to the address in any order, then images stop loading.

I'll give you an example. Here is the code from the main url:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('Catalog.urls')),
    path('arendators/', include('CatalogTenants.urls')),
]


Here is the code from the Catalog project url:
urlpatterns = [
    path('', MainPage.as_view(), name='main'),
    path('QuickOrders', QuickOrdersPage.as_view(), name='quickOrders'),
    path('NetArendators', GetArendators.as_view(), name='netArendators'),
    path('information', Information, name='info'),
    path('Buying', GetBuyPremises.as_view(), name='buying'),
    path('Vacancy', Vacancy, name='vacancy'),
    path('Deal', Deal.as_view(), name='deal')
]

Here all urls are simple, not compound, and everything works here.
But for example, for the CatalogTenants section, I need a compound url. Example 'arendators/offices'
And so I added '/' to the end of the address in the main urls.py to further get the address I need from the CatalogTenants.urls project

And images are not loaded in any of these pages. And the problem is in the URL, because if you remove the '/'' . the pictures load fine. And vice versa, if you add ''/' to any address, then the pictures stop loading.

In settings like this
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'static'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question