title: Cannot upload profile picture in django model
body: <p>I want the user to upload the profile picture on the profile page but it is not storing it in the media/documents folder, and yes, I have put enctype="multipart/form-data" in the html form and the method is post. I'm new to django so please provide a simple solution</p>
  
  <p>models.py</p>
  
  <pre><code>class User(models.Model):
  first_name=models.CharField(max_length=20)
  last_name=models.CharField(max_length=20)
  username=models.CharField(max_length=25, primary_key=True)
  password=models.CharField(max_length=15)
  email_id=models.CharField(max_length=30, default='NULL')
  profile_pic=models.ImageField(upload_to='profilepics/%Y/%m/%d/',height_field=200,width_field=200,default='')
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class ProfilePicForm(forms.ModelForm):
  class Meta:
      model=User
      fields=['username','profile_pic']
  </code></pre>
  
  <p>views.py    </p>
  
  <pre><code>def upload(request):
  if request.method == 'POST':
      username=request.POST['username']
      m=User(username=username)
      m.profile_pic=request.FILES['profile_pic']
      m.save()
      return render(request,'LoginPage/done.html')
  else:
      pic=ProfilePicForm()
      return render(request,'AfterLogin/profile.html')
  </code></pre>
  
  <p>html file</p>
  
  <pre><code>    &lt;form method="POST" enctype="multipart/form-data" action="{% url 'LoginPage:upload' %}"&gt;
          {% csrf_token %}
          &lt;p&gt;Upload your profile photo&lt;/p&gt;&lt;br&gt;
          &lt;input id="id_image" type="file" class="" name="image"&gt;
          &lt;input type="hidden" name="username" value="{{ username }}"&gt;
          &lt;input type="submit" value="Submit"/&gt;
      &lt;/form&gt;
  </code></pre>