What can cause the profile image not show in the template?

All other images are displaying but not the registered user’s profile photo. Why is that?

In my profile template I try to display image like so:

<img src="{{user.profile.profile_image.url}}">

but nothing is showing up.

I followed the Django Authentication And Authorization tutorial.

Might it be some misconfiguration in my settings.py or url.py files?

Ken–Can you help? Are you there/here??

Here are my url.py settings:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('tutorial_base_app.urls')),

    path('membership/', include('membership.urls', namespace='membership')),
    path('membership/', include('django.contrib.auth.urls')),


]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

here is the section of the settings.py where we configure static and media folders:


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/



STATIC_URL = '/static/'

Can someone please help?

There are many reasons this can happen.

What is being rendered in the html? (If you look at that page in your browser’s developer tools, what is in that element on the page?)

Also, you can verify in the Django shell what you’re getting for that expression. Verify that you’re getting a proper url and that it’s pointing to the right location.

What status are you getting for the request in your server?

(Note: If that’s a user-uploaded file, then it’s considered a “media” file and not a “static” file - those are managed differently.)

I don’t know why–but I changed the Profile model relationship to OneToOneField from ForeignKey and it worked.

Now its only visible to logged in users. Strange

nevermind, its working