Can't load the images

27 views
Skip to first unread message

Ramesh Parajuli

unread,
May 27, 2023, 12:28:21 PM5/27/23
to Django users
Please help me:
example.png
Screenshot (9).png
setting static.png

Ryan Nowakowski

unread,
May 27, 2023, 4:49:56 PM5/27/23
to Ramesh Parajuli, Django users
When debugging this kind of thing I usually right click the image and open in new tab.


On May 27, 2023 12:25:47 AM AKDT, Ramesh Parajuli <rameshpa...@gmail.com> wrote:
Please help me:

DieHardMan 300

unread,
May 28, 2023, 9:38:07 PM5/28/23
to Django users
1. Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS
2. also if it already included, adding the following snippet to your urls.py:
-----------------------------------------------------------------------------------------------------------------------
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # others urls,
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
-----------------------------------------------------------------------------------------------------------------------
3. also in your settings.py adding STATIC_ROOT, make sure you have "pathlib" imported above:
-----------------------------------------------------------------------------------------------------------------------
from  pathlib import Path
# ...
# ... other code
# ...
STATIC_URL = "static/"
STATIC_ROOT = Path.joinpath(BASE_DIR, STATIC_URL)
-----------------------------------------------------------------------------------------------------------------------
or if you prefer os module adding this instead in settings.py
-----------------------------------------------------------------------------------------------------------------------
import os
# ...
# ... other code
# ...
STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, STATIC_URL)
-----------------------------------------------------------------------------------------------------------------------
Although this is not suitable for production, only for development.
I hope this help.
ในวันที่ วันเสาร์ที่ 27 พฤษภาคม ค.ศ. 2023 เวลา 23 นาฬิกา 28 นาที 21 วินาที UTC+7 Ramesh Parajuli เขียนว่า:
Please help me:
Reply all
Reply to author
Forward
0 new messages