django - Static folder not being loaded -
i want insert avatar of logged in user header, can't files load. i've checked installed apps, directory should no avail.
here's template:
{% load static staticfiles %} <header> <div id="header_title">app name goes here</div> <div id="header_nav"> <nav> {% if user.is_authenticated %} <a href="home">home</a> <a href="feed">feed</a> <a href="me"> {% load staticfiles %} <img src="{% static 'user/'%}{{request.user}}/avatar.png" alt=""> </a> <a href="notifications">n</a> <a href="settings"> <div>s</div> </a> {% else %} <a href="login">log in</a> <a href="register">register</a> {% endif %} </nav> </div> </header> and settings.py:
... # application definition installed_apps = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'tracks', ... templates = [ { 'backend': 'django.template.backends.django.djangotemplates', 'dirs': [os.path.join(base_dir, 'templates')], 'app_dirs': true, 'options': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'django.core.context_processors.static', 'django.core.context_processors.media', ], }, }, ] ... # static files (css, javascript, images) # https://docs.djangoproject.com/en/1.9/howto/static-files/ static_url = '/static/' auth_profile_module = 'tracks.userprofile' this not show image, instead shows "image not found" icon.
what going on here? why not loading files , displaying them? going url "/static/user/enitoni/avatar.png" gives me 404 error.
here's rendered html if helps:
<a href="me"> <img src="/static/user/enitoni/avatar.png" alt=""> </a>
so... define static_url didn`t define static_root or static_file_dirs. static_url load static files present in dir named 'static' must in your_app like:
my_app/static/my_app/myimage.jpg
and access through
<img src="{% static "my_app/myexample.jpg" %}" alt="my image"/>
if need load static files outside app, check documentation: https://docs.djangoproject.com/en/1.9/howto/static-files/
Comments
Post a Comment