I am currently working on a Django app and I have come across an error that I am unsure how to fix. I have looked about online but still haven't found an answer that suits my code. I am trying to allow users to upload a profile picture however I am not sure why it won't work. The files do not upload to the correct folder and IF they do upload somewhere I am not sure where. I think it may be something to do with the path that is referenced in settings.py and the upload_to in my model. All help is appreciated. Thanks in advance. :)
Image of the directory setup of my files
settings.py file (bottom of it)
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
LOGIN_REDIRECT_URL = 'main:home'
AUTH_USER_MODEL = 'main.Designer'
INTERNAL_IPS = '127.0.0.1'
models.py (Designer Model)
class Designer(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(unique=True)
username = models.CharField(max_length=25, unique=True)
display_name = models.CharField(max_length=25)
twitter = models.CharField(max_length=15)
bio = models.TextField(max_length=145, blank=True, default="")
avatar = models.ImageField(upload_to='img', default='img/default_profile_pic.jpg')
up_votes = models.IntegerField(default=0)
available = models.BooleanField(default=False)
thumbnail_price = models.FloatField(null=True)
channel_art_price = models.FloatField(null=True)
monthly = models.BooleanField(default=False)
promoted = models.BooleanField(default=False)
date_joined = models.DateTimeField(default=timezone.now)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
If there are any other parts you need to see to help solve my problem, please let me know. All help is appreciated.
You need to add
enctype="multipart/form-data"
to your<form>
element in the template, otherwise the browser can't send files to the server.