models.py:
class UserProfile(models.Model):
photo = models.ImageField(upload_to = get_upload_file_name,
storage = OverwriteStorage(),
default = os.path.join(settings.STATIC_ROOT,'images','generic_profile_photo.jpg'),
height_field = 'photo_height',
width_field = 'photo_width')
photo_height = models.PositiveIntegerField(blank = True, default = 0)
photo_width = models.PositiveIntegerField(blank = True, default = 0)
views.py:
def EditProfile(request):
register_generator()
source_file = UserProfile.objects.get(user = request.user).photo
args = {}
args.update(csrf(request))
args.update({'source_file' : source_file})
somewhere in my template:
{% generateimage 'user_profile:thumbnail' source=source_file %}
I receive an error: UserProfile matching query does not exist.
at this line:
source_file = UserProfile.objects.get(user = request.user).photo
The problem is that the default atribute of ImageField is not working. Thus, the object is not created inside my model. How to use this atribute properly? If I ommit this atribute, the object is created with no errors. Do I need to pass the absolute or relative path? I am using django-imagekit to resize the image before dispalying it: http://django-imagekit.readthedocs.org/en/latest/
If you don't define the default attribute, does image uploading work successfully? When I implemented an ImageField in my own django project, I didn't use the default attribute. Instead I wrote this method to get the path to the default image:
Then in the template, display the image with:
EDIT: Simple example
In views.py
Then in the template, include the code
would display the image.
Also for the error 'UserProfile matching query does not exist.' I assumee you have defined a foreign key relationship to the User model somewhere in your UserProfile model, correct?