model - Django ImageField error : cannot open image file -
i put imagefield model , can upload image file. when try open file through admin page. cannot open file there error says "500 internal server error".
in file name there non-ascii letters inside. how can fix problem?
class customer(user): profile_image = models.imagefield(upload_to='customers/photos', null=true, blank=true) hospital = models.foreignkey('hospital', null=true, blank=true) treatments = models.manytomanyfield('treatment', blank=true) verified = models.booleanfield(default=false) def get_full_name(self): return self.email def get_short_name(self): return self.email image file name = "데이비드_베컴2.jpg"
actually model has more 1 field..
+) admin.py
class customeradmin(useradmin): form = customerchangeform add_form = customercreationform # fields used in displaying user model. # these override definitions on base useradmin # reference specific fields on auth.user. list_display = ('email', 'phonenumber', 'is_admin') list_filter = ('is_admin',) fieldsets = ( (none, {'fields': ('email', 'password', 'phonenumber', 'smscheck', 'name', 'hospital', 'major', 'treatments', 'info', 'profile_image', 'verified', )}), ('personal info', {'fields': ()}), ('permissions', {'fields': ('is_active', 'is_admin',)}), ) # add_fieldsets not standard modeladmin attribute. useradmin # overrides get_fieldsets use attribute when creating user. add_fieldsets = ( (none, { 'classes': ('wide',), 'fields': ('email', 'password1', 'password2', 'phonenumber', 'smscheck', 'name', 'hospital', 'major', 'treatments', 'info', 'verified', 'is_active', 'is_admin')} ), ) search_fields = ('email', 'phonenumber') ordering = ('email',) filter_horizontal = ()
also when put file encoded english has no problem.. example, "myprofile.jpg"
+) error in detail
traceback (most recent call last): file "/usr/local/cellar/python/2.7.11/frameworks/python.framework/versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run self.result = application(self.environ, self.start_response) file "/usr/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__ return self.application(environ, start_response) file "/usr/local/lib/python2.7/site-packages/whitenoise/base.py", line 57, in __call__ static_file = self.find_file(environ['path_info']) file "/usr/local/lib/python2.7/site-packages/whitenoise/django.py", line 72, in find_file if self.use_finders , url.startswith(self.static_prefix): unicodedecodeerror: 'ascii' codec can't decode byte 0xeb in position 22: ordinal not in range(128)
how can fix problem? in advance!
finally found solution error.
just implement new custom field yourself.
import unicodedata django.db.models import imagefield class myimagefield(imagefield): def __init__(self, *args, **kwargs): super(myimagefield, self).__init__(*args, **kwargs) def clean(self, *args, **kwargs): data = super(myimagefield, self).clean(*args, **kwargs) data.name = unicodedata.normalize('nfkd', data.name).encode('ascii', 'ignore') return data
for more information u can check out here.
Comments
Post a Comment