0

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.

Jude Molloy
  • 193
  • 3
  • 18
  • Show your template that has the form. You are likely missing the [`enctype="multipart/form-data"`](http://stackoverflow.com/a/4526286/5113242) from your form element. – Anonymous Dec 22 '16 at 02:01
  • You should also provide more detail on the error you are receiving. – ChidG Dec 22 '16 at 02:04
  • Thanks very much that has solved the problem, I didn't know that you had to do that :) Post your comment as an answer and I will accept it. Do you know where I could learn how to make the users editable in the admin? – Jude Molloy Dec 22 '16 at 02:06
  • I'm not sure what you mean by making users editable. You're probably better of asking a new question if it's not something trivial. – Anonymous Dec 22 '16 at 02:08

1 Answers1

2

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.

Community
  • 1
  • 1
Anonymous
  • 11,740
  • 3
  • 40
  • 50