skip to Main Content

details of my code, in my settings.py i have:

BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

and this is how i tried to acces form the template:
in very first page:

% load static % 

to display image,

 <a class="navbar-brand" href="#"><img src="{% static 'images/main.png' %}" alt="imagetwo" width="100" height="50"></a>

anyone who can help me, please

if you need further details of the project structure, from cpanel root, mainfolder/users. users is my app. mainfolder/mydjango mydjango is my dajngo project, both django project and app is at the same directory level! The image is found in mainfolder/users/static/images/

2

Answers


  1. You have just try load image Like,

    Your code:

    <a class="navbar-brand" href="#"><img src="{% static 'images/main.png' %}" alt="imagetwo" width="100" height="50"></a>
    

    Try My Answer:

    <a class="navbar-brand" href="#"><img src="{% static '/images/main.png' %}" alt="imagetwo" width="100" height="50"></a>
    

    Follow my code, to load your images just put / before your folder name and after write your image name.

    Login or Signup to reply.
  2. coul’ve forgoten to add this :

    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    
    urlpatterns += staticfiles_urlpatterns()
    

    to the url.py file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search