title: Saving Image File in particular directory in Django Rest Framework
body: <p>I am using Python PIL library in Django Rest Framework for building qr code and saving it to static directory.</p>
  <pre><code>  def generate_qr(self, name):
      qr = qrcode.QRCode(
          version=1,
          error_correction=qrcode.constants.ERROR_CORRECT_M,
          box_size=15,
          border=5
      )
      qr.add_data(name)
      qr.make(fit=True)
      img = qr.make_image(fill='black', back_color='white')
      img.save(settings.STATIC_ROOT+&quot;/asset-tags/name.png&quot;)
      return(name+ '.png')
  </code></pre>
  <p>settings.py for media and static urls:</p>
  <pre><code>STATIC_URL = '/static/'
  STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
  )
  STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  
  MEDIA_URL = &quot;/mediafiles/&quot;
  MEDIA_ROOT = os.path.join(BASE_DIR, &quot;mediafiles&quot;)
  </code></pre>
  <p>But while saving it throws an error saying /usr/app/static/name.png : no file or directory.
  I am creating new file so how can it find the image in given folder.</p>
  <p>Any Help will be appreciated. Thanks.</p>