I put the ImageField into the Model and can successfully upload the image file. But when try to open the file through admin page. Cannot open the file but there is an error says "500 Internal server error".
In the file name there are some non-ascii letters inside. How can I fix this 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 this model has more then one field..
+) admin.py
class CustomerAdmin(UserAdmin):
form = CustomerChangeForm
add_form = CustomerCreationForm
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that 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 is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a 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 I put the file encoded with english it has no problem.. for 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 and url.startswith(self.static_prefix):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xeb in position 22: ordinal not in range(128)
How can I fix this problem? thanks in advance!