These are my models.py:
def get_profileImage_file_path(instance, filename): return os.path.join('%s/uploadedPhotos/profileImages' % instance.user_id, filename) class UserExtended(models.Model): user = models.OneToOneField(User) profileImage = models.ImageField(upload_to=get_profileImage_file_path, default='/static/images/myProfileIcon.png')
Now I want the default image (which is in my static folder) to be saved to the path specified in
get_profileImage_file_path
function. In my settings.py, I defined media_root and media_URL as:
MEDIA_ROOT = '/home/username/Documents/aSa/userPhotos' MEDIA_URL = '/media/'
For some reason, when I pass the user object in the template and in the template, if I do this:
<img class='profilePic' src="{{ user.userextended.profileImage.url }}" height='120px' alt="" />
No image appears, and when I open the "check item" section in chrome, it gives a 404 error:
GET http://127.0.0.1:8000/home/username/Documents/djcode/aS/aSa/static/images/myProfileIcon.png 404 (NOT FOUND)
although this is the correct path to the file. (Iām also not sure why it gives the whole path to the file, should it not just start with / static /? Even when I "look through the source", the whole URL is there.) How can I make the default image which is located in a static folder, is loaded into the path specified in
get_profileImage_file_path
function?