For image resizing i have used the following function(in bold).Is it right??
def edit_profile(request):
if 'username' in request.session:
#user_id=request.POST.get('id')
user_id=request.GET.get('id')
usr_obj=User.objects.get(id=int(user_id))
if request.method=="POST":
if(request.POST['houseno']!=''):
houseno=request.POST['houseno']
else:
houseno=None
if(request.POST['address1']!=''):
address1=request.POST['address1']
else:
address1=None
if(request.POST['city']!=''):
city=request.POST['city']
else:
city=None
if(request.POST['state']!=''):
state=request.POST['state']
else:
state=None
if(request.POST['pincode']!=''):
pincode=request.POST['pincode']
else:
pincode=None
if(request.POST['country']!=''):
country=request.POST['country']
else:
country=None
if(request.POST['comment']!=''):
comment=request.POST['comment']
else:
comment=None
regform=Edit_Registration(instance=usr_obj,data=request.POST)
if regform.is_valid():
try:
from PIL import Image, ImageOps
except ImportError:
import Image
import ImageOps
imagecontent=request.FILES['image']---At this point it is giving MultiValueDicitionayKeyError(though the field name is same that is image)
if imagecontent.mode not in ("L", "RGB"):
image = imagecontent.convert("RGB")
imageresize = image.resize((100,100), Image.ANTIALIAS)
imageresize.save( 'JPEG', quality=75)
regform.save();
return HttpResponseRedirect('/index/')
else:
return render_to_response("edit_profile.html",{"form":regform,})
else:
regform=Edit_Registration(instance=usr_obj)
return render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})
else:
return HttpResponseRedirect('/login/')
Please Suggest..........
On Tue, Mar 24, 2015 at 6:41 PM, Andreas Kuhne <andreas.kuhne@suitopia.com> wrote:
You can use Pillow to change the size of the images yourself. That is however pretty complicated and IMO not really worth the effort. I would go with easy_thumbnails.--Regards,Andréas2015-03-24 14:04 GMT+01:00 Akash Patni <akash.patni@ranosys.com>:To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANSMZiQoee%2BiM75MU6%2Bw%2BWvZ%2BAYhsHDKAeJdOoo012t7OGoFNA%40mail.gmail.com.can you please suggest me another answer...--On Tue, Mar 24, 2015 at 6:13 PM, Andreas Kuhne <andreas.kuhne@suitopia.com> wrote:--Hi,Check out the easy_thumbnails plugin. http://easy-thumbnails.readthedocs.org/en/2.1/It automatically resizes all images to the size you want if you use it correctly.Regards,Andréas2015-03-24 11:07 GMT+01:00 <akash.patni@ranosys.com>:--Hi..
can anyone please tell me how to resize the uploaded image....
This is my model
class User(models.Model):
first_name=models.CharField(verbose_name = "First Name *",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name *",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email *",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password *",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No *",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House No",max_length=10,blank=True)
address1=models.CharField(verbose_name = "Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name = "Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name = "Country",max_length=30,blank=True)
comment=models.CharField(verbose_name = "Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb) *",blank=True,upload_to='media/')
def __unicode__(self):
return self.first_name
this is my form
class Registration(forms.ModelForm):
password = forms.CharField(label='Password *',widget=forms.PasswordInput())
image = forms.ImageField(label='Select a file *',help_text='max. 1 megabytes')
class Meta:
view.py
def registration(request):
#request.session.set_test_cookie()
if request.method == "POST":
regform=Registration(request.POST,request.FILES)
if regform.is_valid():
#item=resize_and_crop(img_path, modified_path, size, crop_type='top')
regform.save();
return HttpResponseRedirect('/login/')
else:
return render_to_response('registration.html',{"form":regform})
else:
regform=Registration()
return render_to_response('registration.html',{"form":regform})
def show_profile(request):
if 'username' in request.session:
obj_user=User.objects.all().order_by('-id')
return render_to_response("index.html",{"obj_user":obj_user,"message":"Hello World"})
else:
return HttpResponseRedirect('/login/')
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5938a0d0-af8a-44aa-96c4-5d234f3e2cc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/XjuyFyKNnEI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUb%3DJWPh_5Fgk8YiGTsacVLab6xakpEMW2z2GK7xd71PUpA%40mail.gmail.com.--Software EngineerBest Regards,Akash Patni
Head Office:
Oxley Bizhub, #06-48 | 73 Ubi Road 1 | Singapore - 408733
Tel: +65 66331556 | HP: +65 98573420
Global Offices:
San Francisco, USA | Jaipur, India | Bikaner, India
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/XjuyFyKNnEI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUb%3DAh4atvfjz%2B3cJ5VURm1%2BCFqOHfefeMa6EkaKjwieJdA%40mail.gmail.com.
Best Regards,
Akash Patni| | |||||||||
Head Office:
| |||||||||
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANSMZiT9NdTiRk%2BBStEJ%3DeTnRpaBFGBDDvr%2B2Jwpc6%3Db88gEvw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment