Image is not visible on the user profile page

I wrote the code to update user image (default as well as uploaded) on the user profile page. However, it’s not working and just showing some icon instead of the real image. Please can someone help to fix the issue?

In user app: as follows:

from django.db import models
from django.contrib.auth.models import User

class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default=‘profilepic.jpg’, upload_to=‘profile_pictures’)
location = models.CharField(max_length=100)
def str(self):
return self.user.username

In main app (root)

MEDIA_ROOT = os.path.join(BASE_DIR,‘pictures’)
MEDIA_URL = ‘/pictures/’

In root app

from django.contrib import admin
from django.urls import path, include
from users import views as user_views
from django.contrib.auth import views as authentication_views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path(‘food/’, include(‘food.urls’)),
path(‘register/’, user_views.register, name=‘register’),
path(‘login/’, authentication_views.LoginView.as_view(template_name=‘users/login.html’), name=‘login’),
path(‘logout/’, authentication_views.LogoutView.as_view(template_name=‘users/logout.html’), name=‘logout’),
path(‘profile/’, user_views.profilepage, name=‘profile’),

urlpatterns += [
# … the rest of your URLconf goes here …
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)


First, when posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

Couple steps for diagnosis -

1 - Verify that the expected file is in the intended directory
2 - Check to see what the img tag in the rendered page looks like
3 - Look at the request being made for the image in the console to see what is being requested and what the response is.

We may end up needing to see the view(s) and template(s) involved in this.

Thank you, Ken!
I am new on the platform so did not know about the guidelines. But I will make a note of it for the future asks.

I figured out the error by myself. The variable names for static images (MEDIA_URL, MEDIA_ROOT) had mismatch with the variables in urlpatterns in

Thank you for responding to my issue. I am excited to learn Django and contribute to open source projects soon.