Django - images upload in wrong folder

Making some kind of blog website and can't make homepage to show article images... Images should be uploaded to media/profile_pics , but it just makes profile_pics folder in app folder and uploads images there.

my :

class Post(models.Model):
    title = models.CharField(max_length=255)
    title_tag = models.CharField(max_length=255, default="YNTN")
    #author = models.ForeignKey(User, on_delete=models.CASCADE)
    body = RichTextField(blank=True, null=True)
    image = models.ImageField(upload_to="profile_pics", blank=True, null=True)
    #body = models.TextField()
    post_date = models.DateField(auto_now_add=True)
    likes = models.ManyToManyField(User, related_name="blog_posts")

    def total_likes(self):
        return self.likes.count()

    def __str__(self):
        return (self.title + " | " + str(

    def get_absolute_url(self):
        return reverse("home")


class AddPostView(CreateView):
    model = Post
    form_class = PostForm
    template_name = 'add_post.html'


class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ('title', 'title_tag', 'body', 'image')
        widgets = {
            'title': forms.TextInput(attrs={'class':'form-control', 'placeholder':'Title of the Blog'}),
            'title_tag': forms.TextInput(attrs={'class':'form-control', 'placeholder':'Copy the title with no space and a hyphen in between'}),
            'body': forms.Textarea(attrs={'class':'form-control', 'placeholder':'Content of the Blog'}),

my home.html

<div class="row">
    {% for post in object_list %}
    <div class="col-lg-4 my-4">
        <div class="card shadow" style="width: 20rem; height: 33rem;">
            <img src="/media/{{post.image}}" class="card-img-top" alt="..." height="250px">
            <div class="card-body">
              <h5 class="card-title">{{post.title}} <br><small>by {{ }} {{ }}</small></h5>
              <p class="card-text">{{post.body|slice:":100"|safe}}</p>
              <a href={% url 'article-details' %} class="btn btn-primary">Read More {% if user.is_superuser %}<a href="delete_blog_post/{{post.slug}}/" class="btn btn-danger mx-4">Delete Blog</a>{% endif %}</a>
    {% endfor %}


MEDIA_ROOT = os.path.join(BASE_DIR, 'yntn/yntnapp/media')
MEDIA_URL = '/media/'

Images should be in media/profile_pics, but instead, it is making profile_pics folder in my project folder and uploading images there...

I think you should set your MEDIA_ROOT like the following line.

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Because that is where you pointed you model to upload at upload_to="profile_pics". Instead you need to point to yntn/yntnapp/media/profile_pics.

You can do that by importing MEDIA_ROOT variable from settings and concatenate it with profile_pics.

from django.conf import settings

class Post(models.Model):
    image = models.ImageField(upload_to=f"{settings.MEDIA_ROOT}/profile_pics", blank=True, null=True)
Back to Top