render_to decorator usage example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
@render_to('photo_upload.html')
def user_photo(request,nick):
if request.method == 'POST':
form = PhotoUpload(request.POST,request.FILES)
if form.is_valid():
if request.FILES:
today_time = int(time.time())
file1 = StringIO.StringIO(form.cleaned_data['photo_1'].content)
photo_1 = Image.open(file1)
photo_1.thumbnail((100,100))
photo_1.save('/home/offline/django/muzx/static/images/%s.jpg' % today_time,'JPEG')
return HttpResponseRedirect('/profile/')
else:
return HttpResponseRedirect('/profile/')
else:
return {'form':form}
else:
form = PhotoUpload(auto_id=True)
return {'form':form}