Question for Upload images issue
Hi, By using Vuejs, Axios and Django, we're uploading "multiple images" using Vuejs form in one upload/browse attempt. After uploading, the images are getting in a list and then the list of images names are stored into backend in ImageField. The image names are saving into database but not saving into Media Folder. Here is snippet of the code. Vuejs ``` Files {{ name }} Submit ``` Axiox ``` new Vue({ el: '#app', data() { return { files: [], images: [], } }, computed: { filesNames() { const fn = [] for (let i = 0; i < this.files.length; ++i) { fn.push(this.files.item(i).name) } return fn } }, methods: { handleFileUploads(event) { this.files = event.target.files; this.images = [...this.files].map(URL.createObjectURL); }, submitFile() { let formData = new FormData(); for (var i = 0; i < this.files.length; i++) { let file = this.files[i]; formData.append('files[' + i + ']', file); } submitForm: function(){ let formData = new FormData(); const fna = [] for (let i = 0; i < this.files.length; ++i) { fna.push(this.files.item(i).name) } console.log('fna'); console.log(fna); axios({ method : "POST", url: "{% url 'service-ad' %}", headers: {'X-CSRFTOKEN': '{{ csrf_token }}', 'Content-Type': 'multipart/form-data'}, data : { "images": fna, }, }).then(response => { console.log('SUCCESS!!'); }).catch(err => { console.log('FAILURE!!'); }); } } }) ``` Where as in other case we have similar functionality of uploading 'multiple images' in one upload/browse attempt, but here, we are using HTML form and the images names are saved in database as well as in Media Folder. Django ``` def servicevue(request): if request.method == "POST": data = json.loads(request.body) images = data['images'] img_length = len(images) if img_length == 1: image_name = images[0] image_name2 = '' elif img_length == 2: image_name = images[0] image_name2 = images[1] else: image_name = '' image_name2 = '' savehotel = Hotel( image=image_name, image2=image_name2, ) savehotel.save() messages.success(request, """Your Ad is successfully posted.""") return JsonResponse(safe=False) return render(request, 'servicead.html') ``` So we are wondering what could be the issue. We hope our code is correctly implemented. Please help me out whether this is any way to unblock this issue? Best regards, Salima -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABscGkRXhvC6zALxCXvQN6-DmB%2BxedTSWO8KrPS2Nih0imZtXA%40mail.gmail.com.
Re: Upload images
On 12/02/2021 05.12, mtp...@gmail.com wrote: How do I check if the files are valid images or not before creating the organization object. When asking someone for help, at least have the courtesy to reply the suggestions you're given before asking an unrelated question. This will greatly improve the chances of getting help from someone. Kind regards, Kasper Laudrup -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f760733a-5126-efaa-612e-d7c53960c9f0%40stacktrace.dk.
Re: Upload images
How do I check if the files are valid images or not before creating the organization objec On Friday, February 12, 2021 at 12:21:19 AM UTC+3 theresa...@gmail.com wrote: > What is the error message? Is it in your admin site you are getting issues > uploading images or when rendered in the template? > > For me I use this in my model: > image = models.ImageField(null=True, blank=True, upload_to="images/") > > the upload_to specifies wherein the static folder I want to upload the > images > > On Thu, 11 Feb 2021 at 19:30, mtp...@gmail.com wrote: > >> Hello everyone, >> I have implemented an endpoint to register an organization how do I make >> it posssible to upload the images considering the org model as shown below. >> >> ``` >> >> class Organization(Group): >> email = models.EmailField(max_length=60, blank=False, null=False) >> admin = models.ManyToManyField(settings.AUTH_USER_MODEL) >> users = models.ManyToManyField(settings.AUTH_USER_MODEL,related_name >> ='org_users') >> is_active = models.BooleanField(default=False) >> short_name = models.CharField(max_length=200,blank=True) >> location = models.CharField(max_length=200,blank=True, null=True) >> tag_line = models.TextField(null=True,blank=True) >> company_phone = models.CharField(max_length=15, blank=True, null >> =True) >> po_box = models.CharField(max_length=15, blank=True, null=True) >> first_logo = models.ImageField(null=True,blank=True) >> second_logo = models.ImageField(null=True,blank=True) >> third_logo = models.ImageField(null=True,blank=True) >> history = HistoricalRecords() >> >> ``` >> > >> I have implemented the following view but saving the images part is an >> issue: >> >> ``` >> class OrganizationRegistration(generics.CreateAPIView): >> queryset = Organization.objects.all() >> permission_classes = (permissions.AllowAny,) >> serializer_class = OrgRegistrationSerializer >> >> """ >> { >> "admin":{ >> "username":"kapy...@abyssmail.com", >> "first_name":"Cindy", >> "last_name":"Georgia", >> "password":"password", >> "email":"kapy...@abyssmail.com" >> }, >> "org":{ >> "name":"ARIZONA LAW SOCIETY", >> "short_name":"ALS", >> "tag_line":"ALS", >> "email":"kapy...@abyssmail.com", >> "company_phone": "+25475533222", >> "po_box": "200", >> "location":"NAKURU", >> "first_logo": " >> https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg >> ", >> "second_logo": " >> https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg >> ", >> "third_logo": " >> https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg >> " >> } >> } >> """ >> >> def post(self, request, format=None, *args, **kwargs): >> try: >> admins = Group.objects.get(name__iexact='admin') >> admin_role = Role.objects.get(name__iexact="admin") >> >> except: >> # The admin group is >> admins = Group.objects.create(name="admin") >> >> admin_role = Role.objects.create(name="admin") >> >> # Validate USer and Org >> if Organization.objects.filter(name__iexact >> =request.data['org']['name']).exists() is True: >> >> res = {"data": None, "msg":"Organization with that name already >> registered","success": False} >> return Response(data=res,status=status.HTTP_400_BAD_REQUEST) >> >> if User.objects.filter(username__iexact >> =request.data['admin']['username']).exists() is True: >> >> res = {"data": None, "msg":"User with that name already >> registered.","success": False} >> return Response(data=res,status=status.HTTP_400_BAD_REQUEST) >> >> >> try: >> admin = User.objects.create( >> username=request.data['admin']['username'], >> email=request.data['admin']['email'], >> first_name=request.data['admin']['first_name'], >> last_name=request.data['admin']['last_name'], >> ) >> >> location_name = request.data['org']['location'].upper() >> >> location_obj, _ = Location.objects.get_or_create(name >> =location_name) >> area_name = location_obj.name >> >> # Create Random Password >> password = User.objects.make_random_password(length=10) >> >> admin.set_password(password) >> admin.save() >> admin.groups.add(admins) >> admin.roles.add(admin_role) >> except Exception as e: >> return Response(data={"msg":str >> (e),"success":False, "data": None},status=status.HTTP_400_BAD_REQUEST) >> >> try: >> >>
Re: Upload images
How do I check if the files are valid images or not before creating the organization object. On Friday, February 12, 2021 at 12:21:19 AM UTC+3 theresa...@gmail.com wrote: > What is the error message? Is it in your admin site you are getting issues > uploading images or when rendered in the template? > > For me I use this in my model: > image = models.ImageField(null=True, blank=True, upload_to="images/") > > the upload_to specifies wherein the static folder I want to upload the > images > > On Thu, 11 Feb 2021 at 19:30, mtp...@gmail.com wrote: > >> Hello everyone, >> I have implemented an endpoint to register an organization how do I make >> it posssible to upload the images considering the org model as shown below. >> >> ``` >> >> class Organization(Group): >> email = models.EmailField(max_length=60, blank=False, null=False) >> admin = models.ManyToManyField(settings.AUTH_USER_MODEL) >> users = models.ManyToManyField(settings.AUTH_USER_MODEL,related_name >> ='org_users') >> is_active = models.BooleanField(default=False) >> short_name = models.CharField(max_length=200,blank=True) >> location = models.CharField(max_length=200,blank=True, null=True) >> tag_line = models.TextField(null=True,blank=True) >> company_phone = models.CharField(max_length=15, blank=True, null >> =True) >> po_box = models.CharField(max_length=15, blank=True, null=True) >> first_logo = models.ImageField(null=True,blank=True) >> second_logo = models.ImageField(null=True,blank=True) >> third_logo = models.ImageField(null=True,blank=True) >> history = HistoricalRecords() >> >> ``` >> > >> I have implemented the following view but saving the images part is an >> issue: >> >> ``` >> class OrganizationRegistration(generics.CreateAPIView): >> queryset = Organization.objects.all() >> permission_classes = (permissions.AllowAny,) >> serializer_class = OrgRegistrationSerializer >> >> """ >> { >> "admin":{ >> "username":"kapy...@abyssmail.com", >> "first_name":"Cindy", >> "last_name":"Georgia", >> "password":"password", >> "email":"kapy...@abyssmail.com" >> }, >> "org":{ >> "name":"ARIZONA LAW SOCIETY", >> "short_name":"ALS", >> "tag_line":"ALS", >> "email":"kapy...@abyssmail.com", >> "company_phone": "+25475533222", >> "po_box": "200", >> "location":"NAKURU", >> "first_logo": " >> https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg >> ", >> "second_logo": " >> https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg >> ", >> "third_logo": " >> https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg >> " >> } >> } >> """ >> >> def post(self, request, format=None, *args, **kwargs): >> try: >> admins = Group.objects.get(name__iexact='admin') >> admin_role = Role.objects.get(name__iexact="admin") >> >> except: >> # The admin group is >> admins = Group.objects.create(name="admin") >> >> admin_role = Role.objects.create(name="admin") >> >> # Validate USer and Org >> if Organization.objects.filter(name__iexact >> =request.data['org']['name']).exists() is True: >> >> res = {"data": None, "msg":"Organization with that name already >> registered","success": False} >> return Response(data=res,status=status.HTTP_400_BAD_REQUEST) >> >> if User.objects.filter(username__iexact >> =request.data['admin']['username']).exists() is True: >> >> res = {"data": None, "msg":"User with that name already >> registered.","success": False} >> return Response(data=res,status=status.HTTP_400_BAD_REQUEST) >> >> >> try: >> admin = User.objects.create( >> username=request.data['admin']['username'], >> email=request.data['admin']['email'], >> first_name=request.data['admin']['first_name'], >> last_name=request.data['admin']['last_name'], >> ) >> >> location_name = request.data['org']['location'].upper() >> >> location_obj, _ = Location.objects.get_or_create(name >> =location_name) >> area_name = location_obj.name >> >> # Create Random Password >> password = User.objects.make_random_password(length=10) >> >> admin.set_password(password) >> admin.save() >> admin.groups.add(admins) >> admin.roles.add(admin_role) >> except Exception as e: >> return Response(data={"msg":str >> (e),"success":False, "data": None},status=status.HTTP_400_BAD_REQUEST) >> >> try: >> >>
Re: Upload images
What is the error message? Is it in your admin site you are getting issues uploading images or when rendered in the template? For me I use this in my model: image = models.ImageField(null=True, blank=True, upload_to="images/") the upload_to specifies wherein the static folder I want to upload the images On Thu, 11 Feb 2021 at 19:30, mtp...@gmail.com wrote: > Hello everyone, > I have implemented an endpoint to register an organization how do I make > it posssible to upload the images considering the org model as shown below. > > ``` > > class Organization(Group): > email = models.EmailField(max_length=60, blank=False, null=False) > admin = models.ManyToManyField(settings.AUTH_USER_MODEL) > users = models.ManyToManyField(settings.AUTH_USER_MODEL,related_name > ='org_users') > is_active = models.BooleanField(default=False) > short_name = models.CharField(max_length=200,blank=True) > location = models.CharField(max_length=200,blank=True, null=True) > tag_line = models.TextField(null=True,blank=True) > company_phone = models.CharField(max_length=15, blank=True, null > =True) > po_box = models.CharField(max_length=15, blank=True, null=True) > first_logo = models.ImageField(null=True,blank=True) > second_logo = models.ImageField(null=True,blank=True) > third_logo = models.ImageField(null=True,blank=True) > history = HistoricalRecords() > > ``` > > I have implemented the following view but saving the images part is an > issue: > > ``` > class OrganizationRegistration(generics.CreateAPIView): > queryset = Organization.objects.all() > permission_classes = (permissions.AllowAny,) > serializer_class = OrgRegistrationSerializer > > """ > { > "admin":{ > "username":"kapyj...@abyssmail.com", > "first_name":"Cindy", > "last_name":"Georgia", > "password":"password", > "email":"kapyj...@abyssmail.com" > }, > "org":{ > "name":"ARIZONA LAW SOCIETY", > "short_name":"ALS", > "tag_line":"ALS", > "email":"kapyj...@abyssmail.com", > "company_phone": "+25475533222", > "po_box": "200", > "location":"NAKURU", > "first_logo": " > https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg > ", > "second_logo": " > https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg > ", > "third_logo": " > https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg > " > } > } > """ > > def post(self, request, format=None, *args, **kwargs): > try: > admins = Group.objects.get(name__iexact='admin') > admin_role = Role.objects.get(name__iexact="admin") > > except: > # The admin group is > admins = Group.objects.create(name="admin") > > admin_role = Role.objects.create(name="admin") > > # Validate USer and Org > if Organization.objects.filter(name__iexact > =request.data['org']['name']).exists() is True: > > res = {"data": None, "msg":"Organization with that name already > registered","success": False} > return Response(data=res,status=status.HTTP_400_BAD_REQUEST) > > if User.objects.filter(username__iexact > =request.data['admin']['username']).exists() is True: > > res = {"data": None, "msg":"User with that name already > registered.","success": False} > return Response(data=res,status=status.HTTP_400_BAD_REQUEST) > > > try: > admin = User.objects.create( > username=request.data['admin']['username'], > email=request.data['admin']['email'], > first_name=request.data['admin']['first_name'], > last_name=request.data['admin']['last_name'], > ) > > location_name = request.data['org']['location'].upper() > > location_obj, _ = Location.objects.get_or_create(name > =location_name) > area_name = location_obj.name > > # Create Random Password > password = User.objects.make_random_password(length=10) > > admin.set_password(password) > admin.save() > admin.groups.add(admins) > admin.roles.add(admin_role) > except Exception as e: > return Response(data={"msg":str > (e),"success":False, "data": None},status=status.HTTP_400_BAD_REQUEST) > > try: > > first_file_logo = request.data['org']['first_logo'] > second_file_logo = request.data['org']['second_logo'] > third_file_logo = request.data['org']['third_logo'] > > org = Organization.objects.create( > name=request.data['org']['name'], > email=request.data['org']['email'], >
Re: Upload images
On 11/02/2021 19.29, mtp...@gmail.com wrote: I have implemented the following view but saving the images part is an issue: What's the issue? Knowing that would make it easier for someone to help you. Having a quick look at the code, I would start by removing the try/except block until you have a way to actually handle the errors you expect to encounter. Currently you either ignore exceptions making it impossible to debug errors, or catch them and tell the client/user that they're to blame for whatever unknown exception was raised (with a 400 status code) without leaving any trace of what actually went wrong for you to fix. That's not error handling. Kind regards, Kasper Laudrup -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8eabb032-3867-cadc-a74b-dcf9256ad6e9%40stacktrace.dk.
Upload images
Hello everyone, I have implemented an endpoint to register an organization how do I make it posssible to upload the images considering the org model as shown below. ``` class Organization(Group): email = models.EmailField(max_length=60, blank=False, null=False) admin = models.ManyToManyField(settings.AUTH_USER_MODEL) users = models.ManyToManyField(settings.AUTH_USER_MODEL,related_name ='org_users') is_active = models.BooleanField(default=False) short_name = models.CharField(max_length=200,blank=True) location = models.CharField(max_length=200,blank=True, null=True) tag_line = models.TextField(null=True,blank=True) company_phone = models.CharField(max_length=15, blank=True, null=True) po_box = models.CharField(max_length=15, blank=True, null=True) first_logo = models.ImageField(null=True,blank=True) second_logo = models.ImageField(null=True,blank=True) third_logo = models.ImageField(null=True,blank=True) history = HistoricalRecords() ``` I have implemented the following view but saving the images part is an issue: ``` class OrganizationRegistration(generics.CreateAPIView): queryset = Organization.objects.all() permission_classes = (permissions.AllowAny,) serializer_class = OrgRegistrationSerializer """ { "admin":{ "username":"kapyj...@abyssmail.com", "first_name":"Cindy", "last_name":"Georgia", "password":"password", "email":"kapyj...@abyssmail.com" }, "org":{ "name":"ARIZONA LAW SOCIETY", "short_name":"ALS", "tag_line":"ALS", "email":"kapyj...@abyssmail.com", "company_phone": "+25475533222", "po_box": "200", "location":"NAKURU", "first_logo": "https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg;, "second_logo": "https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg;, "third_logo": "https://www.mintformations.co.uk/blog/wp-content/uploads/2020/05/shutterstock_583717939.jpg; } } """ def post(self, request, format=None, *args, **kwargs): try: admins = Group.objects.get(name__iexact='admin') admin_role = Role.objects.get(name__iexact="admin") except: # The admin group is admins = Group.objects.create(name="admin") admin_role = Role.objects.create(name="admin") # Validate USer and Org if Organization.objects.filter(name__iexact =request.data['org']['name']).exists() is True: res = {"data": None, "msg":"Organization with that name already registered","success": False} return Response(data=res,status=status.HTTP_400_BAD_REQUEST) if User.objects.filter(username__iexact =request.data['admin']['username']).exists() is True: res = {"data": None, "msg":"User with that name already registered.","success": False} return Response(data=res,status=status.HTTP_400_BAD_REQUEST) try: admin = User.objects.create( username=request.data['admin']['username'], email=request.data['admin']['email'], first_name=request.data['admin']['first_name'], last_name=request.data['admin']['last_name'], ) location_name = request.data['org']['location'].upper() location_obj, _ = Location.objects.get_or_create(name =location_name) area_name = location_obj.name # Create Random Password password = User.objects.make_random_password(length=10) admin.set_password(password) admin.save() admin.groups.add(admins) admin.roles.add(admin_role) except Exception as e: return Response(data={"msg":str (e),"success":False, "data": None},status=status.HTTP_400_BAD_REQUEST) try: first_file_logo = request.data['org']['first_logo'] second_file_logo = request.data['org']['second_logo'] third_file_logo = request.data['org']['third_logo'] org = Organization.objects.create( name=request.data['org']['name'], email=request.data['org']['email'], location=request.data['org']['location'], short_name = request.data['org']['short_name'], tag_line = request.data['org']['tag_line'], company_phone = request.data['org']['company_phone'], po_box = request.data['org']['po_box'], first_logo = first_file_logo, second_logo =second_file_logo , third_logo = third_file_logo ) admin.org_id = org.id admin.save() # add the user creating the
Re: guys help me please, I cannot upload images from django form,
ok bro I'll try it, thanks for now On Sat, Aug 29, 2020 at 7:53 PM Jonathan Villavicencio < codejonvi...@gmail.com> wrote: > Hello! > in the class Posts in the field "image" add upload_to=upload_path for > example: > image = models.ImageField(blank=True, null=True, verbose_name='surat', > upload_to=upload_path) > > upload_path is a method > write it before of the class definition > def upload_path(instance, filename): > return '/'.join([instance.image, filename]) > > El sáb., 29 de ago. de 2020 a la(s) 11:16, allaberdi...@gmail.com ( > allaberdi16yazha...@gmail.com) escribió: > >> I can upload images from django admin panel but cannot to do same thing >> with django form , it saves any text but did not save images only, anyone >> help me please >> this is my code: >> >> models.py: >> class Posts(models.Model): >> >> Ahal = 'Ahal' >> Balkan = 'Balkan' >> Dasoguz = 'Dasoguz' >> Lebap = 'Lebap' >> Mary = 'Mary' >> >> >> CHOOSE_REGION = { >> (Ahal,'Ahal'), >> (Balkan,'Balkan'), >> (Dasoguz,'Dasoguz'), >> (Lebap,'Lebap'), >> (Mary,'Mary') >> } >> >> >> name = models.CharField(max_length=30, blank=False, verbose_name='Ady') >> image = models.ImageField(blank=True, null=True, verbose_name='surat') >> text = models.TextField(verbose_name='gosmaça maglumat') >> price = models.FloatField(verbose_name='bahasy') >> region = models.CharField(max_length=30, choices=CHOOSE_REGION, >> blank=False, verbose_name='welaýat') >> district = models.CharField(max_length=30, blank=False, >> verbose_name='etrab') >> user = models.ForeignKey(User, on_delete=models.CASCADE, >> verbose_name='eýesi') >> phone = models.CharField(max_length=50, blank=False, >> verbose_name='telefon belgisi') >> published = models.DateTimeField(auto_now=True, verbose_name='satuwa >> çykan guni') >> >> >> >> forms.py: >> class PostForm(forms.ModelForm): >> class Meta: >> model = Posts >> fields = >> ['name','image','text','price','region','district','user','phone'] >> >> >> views.py: >> def add_post(request): >> form = PostForm(request.POST or None) >> if form.is_valid(): >> form.save() >> template = 'add_post.html' >> context = {'form':form} >> return render(request,template,context) >> >> settings.py: >> >> STATIC_URL = '/static/' >> STATICFILES_DIR = [Path(BASE_DIR,'static')] >> >> MEDIA_URL = '/media/' >> MEDIA_ROOT = Path(BASE_DIR,'media') >> >> >> urls.py: >> >> from django.conf.urls.static import static >> from django.conf import settings >> >> urlpatterns = [ >> path('admin/', admin.site.urls), >> path('', include('posts.urls')), >> ] >> >> urlpatterns += static(settings.MEDIA_URL, >> document_root=settings.MEDIA_ROOT) >> >> >> >> html form tag: >> {% extends 'index.html' %} >> >> {% load static %} >> >> {% block content %} >> >> >> {% csrf_token %} >> {{form.media}} >> {{form.as_p}} >> >> >> >> {% endblock %} >> >> -- >> 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+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/ad47578f-64a8-40b5-b72b-f3eebb668dben%40googlegroups.com >> <https://groups.google.com/d/msgid/django-users/ad47578f-64a8-40b5-b72b-f3eebb668dben%40googlegroups.com?utm_medium=email_source=footer> >> . >> > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAAEkprV7PmRfkHyMD4VS%3DiN6S%2BjGUwaoaWrkxQ2fhWWXOoHc9Q%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAAEkprV7PmRfkHyMD4VS%3DiN6S%2BjGUwaoaWrkxQ2fhWWXOoHc9Q%40mail.gmail.com?utm_medium=email_source=footer> > . > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJwZnddD5EHO%3DLADx-wGF3s_HopVOi31Wqjot3UgbSspUR-9yw%40mail.gmail.com.
Re: guys help me please, I cannot upload images from django form,
Hello! in the class Posts in the field "image" add upload_to=upload_path for example: image = models.ImageField(blank=True, null=True, verbose_name='surat', upload_to=upload_path) upload_path is a method write it before of the class definition def upload_path(instance, filename): return '/'.join([instance.image, filename]) El sáb., 29 de ago. de 2020 a la(s) 11:16, allaberdi...@gmail.com ( allaberdi16yazha...@gmail.com) escribió: > I can upload images from django admin panel but cannot to do same thing > with django form , it saves any text but did not save images only, anyone > help me please > this is my code: > > models.py: > class Posts(models.Model): > > Ahal = 'Ahal' > Balkan = 'Balkan' > Dasoguz = 'Dasoguz' > Lebap = 'Lebap' > Mary = 'Mary' > > > CHOOSE_REGION = { > (Ahal,'Ahal'), > (Balkan,'Balkan'), > (Dasoguz,'Dasoguz'), > (Lebap,'Lebap'), > (Mary,'Mary') > } > > > name = models.CharField(max_length=30, blank=False, verbose_name='Ady') > image = models.ImageField(blank=True, null=True, verbose_name='surat') > text = models.TextField(verbose_name='gosmaça maglumat') > price = models.FloatField(verbose_name='bahasy') > region = models.CharField(max_length=30, choices=CHOOSE_REGION, > blank=False, verbose_name='welaýat') > district = models.CharField(max_length=30, blank=False, > verbose_name='etrab') > user = models.ForeignKey(User, on_delete=models.CASCADE, > verbose_name='eýesi') > phone = models.CharField(max_length=50, blank=False, verbose_name='telefon > belgisi') > published = models.DateTimeField(auto_now=True, verbose_name='satuwa çykan > guni') > > > > forms.py: > class PostForm(forms.ModelForm): > class Meta: > model = Posts > fields = ['name','image','text','price','region','district','user','phone'] > > > views.py: > def add_post(request): > form = PostForm(request.POST or None) > if form.is_valid(): > form.save() > template = 'add_post.html' > context = {'form':form} > return render(request,template,context) > > settings.py: > > STATIC_URL = '/static/' > STATICFILES_DIR = [Path(BASE_DIR,'static')] > > MEDIA_URL = '/media/' > MEDIA_ROOT = Path(BASE_DIR,'media') > > > urls.py: > > from django.conf.urls.static import static > from django.conf import settings > > urlpatterns = [ > path('admin/', admin.site.urls), > path('', include('posts.urls')), > ] > > urlpatterns += static(settings.MEDIA_URL, > document_root=settings.MEDIA_ROOT) > > > > html form tag: > {% extends 'index.html' %} > > {% load static %} > > {% block content %} > > > {% csrf_token %} > {{form.media}} > {{form.as_p}} > > > > {% endblock %} > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/ad47578f-64a8-40b5-b72b-f3eebb668dben%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/ad47578f-64a8-40b5-b72b-f3eebb668dben%40googlegroups.com?utm_medium=email_source=footer> > . > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAEkprV7PmRfkHyMD4VS%3DiN6S%2BjGUwaoaWrkxQ2fhWWXOoHc9Q%40mail.gmail.com.
guys help me please, I cannot upload images from django form,
I can upload images from django admin panel but cannot to do same thing with django form , it saves any text but did not save images only, anyone help me please this is my code: models.py: class Posts(models.Model): Ahal = 'Ahal' Balkan = 'Balkan' Dasoguz = 'Dasoguz' Lebap = 'Lebap' Mary = 'Mary' CHOOSE_REGION = { (Ahal,'Ahal'), (Balkan,'Balkan'), (Dasoguz,'Dasoguz'), (Lebap,'Lebap'), (Mary,'Mary') } name = models.CharField(max_length=30, blank=False, verbose_name='Ady') image = models.ImageField(blank=True, null=True, verbose_name='surat') text = models.TextField(verbose_name='gosmaça maglumat') price = models.FloatField(verbose_name='bahasy') region = models.CharField(max_length=30, choices=CHOOSE_REGION, blank=False, verbose_name='welaýat') district = models.CharField(max_length=30, blank=False, verbose_name='etrab') user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='eýesi') phone = models.CharField(max_length=50, blank=False, verbose_name='telefon belgisi') published = models.DateTimeField(auto_now=True, verbose_name='satuwa çykan guni') forms.py: class PostForm(forms.ModelForm): class Meta: model = Posts fields = ['name','image','text','price','region','district','user','phone'] views.py: def add_post(request): form = PostForm(request.POST or None) if form.is_valid(): form.save() template = 'add_post.html' context = {'form':form} return render(request,template,context) settings.py: STATIC_URL = '/static/' STATICFILES_DIR = [Path(BASE_DIR,'static')] MEDIA_URL = '/media/' MEDIA_ROOT = Path(BASE_DIR,'media') urls.py: from django.conf.urls.static import static from django.conf import settings urlpatterns = [ path('admin/', admin.site.urls), path('', include('posts.urls')), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) html form tag: {% extends 'index.html' %} {% load static %} {% block content %} {% csrf_token %} {{form.media}} {{form.as_p}} {% endblock %} -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ad47578f-64a8-40b5-b72b-f3eebb668dben%40googlegroups.com.
Re: Upload Images from Remote Server
hi Coues, that's helped me alot thank you for your Solution. On Wed, Nov 23, 2016 at 1:16 AM, ludovic coueswrote: > If you start django by running "python manage.py runserver", you > should have some log message where you have typed the command. > When your program raise an error, like no such file, django should > print a stacktrace in the log. It's a list of all the function that > django called before getting the error. That help a lot when dealing > with error. > > 2016-11-22 12:15 GMT+01:00 pradam programming < > pradam.programm...@gmail.com>: > > Hi Ludovic, > > What is Full stacktrace ..? i tried very solution but i can't able to > store > > image without a form in rest framework..? > > > > On Tue, Nov 22, 2016 at 2:56 PM, ludovic coues wrote: > >> > >> The actual full stacktrace and at least the relevant function in your > >> code would be nice. > >> > >> 2016-11-21 14:09 GMT+01:00 pradam programming > >> : > >> > hi Guys, > >> > 1.I have Created an API which store images into database just giving > >> > image > >> > path but issue is when i remotely upload image using API i will get > the > >> > following error show no such file or Directory eg: > >> > [ > >> > > >> > {'name':'foo','date':'2016-11-21','organization_name':'buzz' > ,'description':'Abhilash','image':'/home/mahiti/Pictures/torrentz.png'}] > >> > > >> > error: > >> > > >> > no file or directory > >> > > >> > 2.How can i remotely get images and save it my local system? > >> > 3.If the site goes live then same scenario will happen as of 1 ? > >> > > >> > -- > >> > 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+unsubscr...@googlegroups.com. > >> > To post to this group, send email to django-users@googlegroups.com. > >> > Visit this group at https://groups.google.com/group/django-users. > >> > To view this discussion on the web visit > >> > > >> > https://groups.google.com/d/msgid/django-users/CAGGVXBOiiVFr7j- > fCXm73NzADgjPFieA4A8ggvATK_SNMwcNMQ%40mail.gmail.com. > >> > For more options, visit https://groups.google.com/d/optout. > >> > >> > >> > >> -- > >> > >> Cordialement, Coues Ludovic > >> +336 148 743 42 > >> > >> -- > >> 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+unsubscr...@googlegroups.com. > >> To post to this group, send email to django-users@googlegroups.com. > >> Visit this group at https://groups.google.com/group/django-users. > >> To view this discussion on the web visit > >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTb- > 3GXvN%3D%3DzK%3DGx0kVQ0%3Dz9YZrN4JQP9_nJv0HebdwUwg%40mail.gmail.com. > >> For more options, visit https://groups.google.com/d/optout. > > > > > > -- > > 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+unsubscr...@googlegroups.com. > > To post to this group, send email to django-users@googlegroups.com. > > Visit this group at https://groups.google.com/group/django-users. > > To view this discussion on the web visit > > https://groups.google.com/d/msgid/django-users/ > CAGGVXBPbvniWgCeuMP8Jd57e_gyWK%3DQ_hbJSNrp_axEZaucfpw%40mail.gmail.com. > > > > For more options, visit https://groups.google.com/d/optout. > > > > -- > > Cordialement, Coues Ludovic > +336 148 743 42 > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/CAEuG%2BTbXpqF-va7sk7Lm94f5Dzyy64yqHTr% > 3DcMY3pTNqbdDyMA%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGGVXBPKS7EhUNXn7iXosmxyUAHz5qGqnvijStPV9VNHxFvCWQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Upload Images from Remote Server
If you start django by running "python manage.py runserver", you should have some log message where you have typed the command. When your program raise an error, like no such file, django should print a stacktrace in the log. It's a list of all the function that django called before getting the error. That help a lot when dealing with error. 2016-11-22 12:15 GMT+01:00 pradam programming: > Hi Ludovic, > What is Full stacktrace ..? i tried very solution but i can't able to store > image without a form in rest framework..? > > On Tue, Nov 22, 2016 at 2:56 PM, ludovic coues wrote: >> >> The actual full stacktrace and at least the relevant function in your >> code would be nice. >> >> 2016-11-21 14:09 GMT+01:00 pradam programming >> : >> > hi Guys, >> > 1.I have Created an API which store images into database just giving >> > image >> > path but issue is when i remotely upload image using API i will get the >> > following error show no such file or Directory eg: >> > [ >> > >> > {'name':'foo','date':'2016-11-21','organization_name':'buzz','description':'Abhilash','image':'/home/mahiti/Pictures/torrentz.png'}] >> > >> > error: >> > >> > no file or directory >> > >> > 2.How can i remotely get images and save it my local system? >> > 3.If the site goes live then same scenario will happen as of 1 ? >> > >> > -- >> > 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+unsubscr...@googlegroups.com. >> > To post to this group, send email to django-users@googlegroups.com. >> > Visit this group at https://groups.google.com/group/django-users. >> > To view this discussion on the web visit >> > >> > https://groups.google.com/d/msgid/django-users/CAGGVXBOiiVFr7j-fCXm73NzADgjPFieA4A8ggvATK_SNMwcNMQ%40mail.gmail.com. >> > For more options, visit https://groups.google.com/d/optout. >> >> >> >> -- >> >> Cordialement, Coues Ludovic >> +336 148 743 42 >> >> -- >> 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+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTb-3GXvN%3D%3DzK%3DGx0kVQ0%3Dz9YZrN4JQP9_nJv0HebdwUwg%40mail.gmail.com. >> For more options, visit https://groups.google.com/d/optout. > > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAGGVXBPbvniWgCeuMP8Jd57e_gyWK%3DQ_hbJSNrp_axEZaucfpw%40mail.gmail.com. > > For more options, visit https://groups.google.com/d/optout. -- Cordialement, Coues Ludovic +336 148 743 42 -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTbXpqF-va7sk7Lm94f5Dzyy64yqHTr%3DcMY3pTNqbdDyMA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Upload Images from Remote Server
Hi Ludovic, What is Full stacktrace ..? i tried very solution but i can't able to store image without a form in rest framework..? On Tue, Nov 22, 2016 at 2:56 PM, ludovic coueswrote: > The actual full stacktrace and at least the relevant function in your > code would be nice. > > 2016-11-21 14:09 GMT+01:00 pradam programming < > pradam.programm...@gmail.com>: > > hi Guys, > > 1.I have Created an API which store images into database just giving > image > > path but issue is when i remotely upload image using API i will get the > > following error show no such file or Directory eg: > > [ > > {'name':'foo','date':'2016-11-21','organization_name':'buzz' > ,'description':'Abhilash','image':'/home/mahiti/Pictures/torrentz.png'}] > > > > error: > > > > no file or directory > > > > 2.How can i remotely get images and save it my local system? > > 3.If the site goes live then same scenario will happen as of 1 ? > > > > -- > > 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+unsubscr...@googlegroups.com. > > To post to this group, send email to django-users@googlegroups.com. > > Visit this group at https://groups.google.com/group/django-users. > > To view this discussion on the web visit > > https://groups.google.com/d/msgid/django-users/CAGGVXBOiiVFr7j- > fCXm73NzADgjPFieA4A8ggvATK_SNMwcNMQ%40mail.gmail.com. > > For more options, visit https://groups.google.com/d/optout. > > > > -- > > Cordialement, Coues Ludovic > +336 148 743 42 > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/CAEuG%2BTb-3GXvN%3D%3DzK%3DGx0kVQ0% > 3Dz9YZrN4JQP9_nJv0HebdwUwg%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGGVXBPbvniWgCeuMP8Jd57e_gyWK%3DQ_hbJSNrp_axEZaucfpw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Upload Images from Remote Server
The actual full stacktrace and at least the relevant function in your code would be nice. 2016-11-21 14:09 GMT+01:00 pradam programming: > hi Guys, > 1.I have Created an API which store images into database just giving image > path but issue is when i remotely upload image using API i will get the > following error show no such file or Directory eg: > [ > {'name':'foo','date':'2016-11-21','organization_name':'buzz','description':'Abhilash','image':'/home/mahiti/Pictures/torrentz.png'}] > > error: > > no file or directory > > 2.How can i remotely get images and save it my local system? > 3.If the site goes live then same scenario will happen as of 1 ? > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAGGVXBOiiVFr7j-fCXm73NzADgjPFieA4A8ggvATK_SNMwcNMQ%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- Cordialement, Coues Ludovic +336 148 743 42 -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTb-3GXvN%3D%3DzK%3DGx0kVQ0%3Dz9YZrN4JQP9_nJv0HebdwUwg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Upload Images from Remote Server
hi Guys, 1.I have Created an API which store images into database just giving image path but issue is when i remotely upload image using API i will get the following error show no such file or Directory eg: [ {'name':'foo','date':'2016-11-21','organization_name':'buzz','description':'Abhilash','image':'/home/mahiti/Pictures/torrentz.png'}] error: no file or directory 2.How can i remotely get images and save it my local system? 3.If the site goes live then same scenario will happen as of 1 ? -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGGVXBOiiVFr7j-fCXm73NzADgjPFieA4A8ggvATK_SNMwcNMQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: How to use Python Requests Module to upload images to Django Application?
My Python code started working after I changed on line. Changing: files_dct = {filename:fobj} to: files_dct = {('photo',(filename, fobj,'image/jpg'))} Now it works. My conjecture about the need for different HTTP-headers was wrong. The working code has not changed the headers received by Django. I must say, the Requests module documentation is very opaque! I made this change based on a guess while reading the docs about sending multiple files. I can't say I understand what going on. Please comment on the right way to do this. > > -- 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+unsubscr...@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/ab20873c-7e7e-4817-82f8-1a691a2cfa14%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to use Python Requests Module to upload images to Django Application?
I am developing a django application that primarily uses web browsers to upload scientific data that includes some image files. Currently, the application works fine when Firefox or Chrome are used. Both images and other data are correctly uploaded. Occasionally users need to upload larger amounts of data, so I want to automate this using Python's Requests module. My python program currently uploads non-image data, but Django is not receiving the image files. This may be because I am not setting HTTP-headers correctly. When the user agent is Firefox, requests received by Django include headers like: HTTP_ACCEPT_ENCODING gzip, deflate HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 When the user agent is my standalone program, only: HTTP_ACCEPT_ENCODING identity My questions are: 1) What HTTP-headers is Django expecting? 2) Should I be gzipping the image files? 3) What is the correct way to do this? A code snippet from my standalone program follows. == # loop to get messages from console while True: message = input("Enter msg string: ") filename= input("Enter filename (or blank): ") # GET print("--- GET upload_msg") # Create a GET request (but do don't sent it) req = Request('GET', upload_msg_url, data= {}) # Send request forms_dct= get_response(req) # modify forms_dct from GET, and use in next get_response() forms_dct['message_str'] = message # open file for upload fobj = open(filename,'rb') # modify forms_dct from GET, and use in next get_response() forms_dct['photo'] = filename # Create files dictionary files_dct = {filename:fobj} # POST print("--- POST upload_msg") # Create a POST request (but do don't sent it) req = Request('POST', upload_msg_url, data= forms_dct, files= files_dct) # Send request forms_dct = get_response(req) # close file fobj.close() == Thanks. -- 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+unsubscr...@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/79a3f85c-b85a-44d1-b7d6-bf150eb35978%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Subtitle upload images
Hi, On 14/08/2013 12:11, Hélio Miranda wrote: Hi I have a problem, that I am not able to solve it is: I'm uploading pictures, and wanted to introduce their legends too, so did the following, which was a preview of the images to the user before uploading. My html code is this: http://plnkr.co/edit/fm0hAZFkVUE7zA3BnZLw?p=preview When you populate your div#result with previews of selected images, you add an input text field with always the same 'name' attribute. Those 'name' attributes should have unique value for each input text field (and not always name="legend"). And this preview is that there is. Now in my view, I have this code: http://plnkr.co/edit/u8ZSrFJCCKFO1PjhO8Tw?p=preview The problem that happens is that it does well upload the photos without problem but the subtitles he inserts in every picture the caption that is only in the last. And then, in your django view, you have to use request.POST['the_unique_name_attribute_for_that_photo'] to get the legend for a particular photo. -- Laurent Meunier-- 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+unsubscr...@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. For more options, visit https://groups.google.com/groups/opt_out.
Subtitle upload images
Hi I have a problem, that I am not able to solve it is: I'm uploading pictures, and wanted to introduce their legends too, so did the following, which was a preview of the images to the user before uploading. My html code is this: http://plnkr.co/edit/fm0hAZFkVUE7zA3BnZLw?p=preview And this preview is that there is. Now in my view, I have this code: http://plnkr.co/edit/u8ZSrFJCCKFO1PjhO8Tw?p=preview The problem that happens is that it does well upload the photos without problem but the subtitles he inserts in every picture the caption that is only in the last. I made myself clear? Someone can help me? thank you Helio Miranda -- 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+unsubscr...@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. For more options, visit https://groups.google.com/groups/opt_out.
Unable to upload images via customized form
Hi all, I am creating a form ( a customized one ) which tries to upload ( bind ) an image file and save the file into my directory ( and its location in mysql database ) The code is right here : # views.py def customized_form(request): if request.method == 'POST': form = CustomizedForm(request.POST, request.FILES) if form.is_valid(): # here create the data object pressrelease = PressRelease.objects.create( title = form.cleaned_data['title'], body = form.cleaned_data['body'], images = form.cleaned_data['images'], user = request.user, ) pressrelease.save() return HttpResponseRedirect('/upload_form_success/') else: form = CustomizedForm() variables = RequestContext(request,{'form':form}) return render_to_response('upload_form.html',variables) #forms.py class CustomizedForm(forms.Form): title = forms.CharField(max_length=100) body = forms.CharField() images = forms.FileField() #models.py class PressRelease(models.Model): title = models.CharField(max_length=100) body = models.TextField() images = models.ImageField(upload_to='userimages') user = models.ForeignKey(User) #upload_form.html {{ form.as_p }} After submitting the form, the mysql database gets populated with the required data, including the file name ( but not location ) I've check the 'userimages' folder and found out that none of the uploaded images are being saved into the 'userimages' folder. Can any one guide me on how to upload files ( image files ) and save it to a directory and with it's location in the mysql database? I need to be able to retrive the files as well. PS: i understand i can do it by creating a form out of the model class but i just wanted to learn more about the forms api. Thank you for your time! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Upload images to database
Yes, I need to store them in database. I need to do this from the django admin. Do I have to make a custom field in the model? Or additional field in the database which is blob type? How can I override the save method , so that the image to be uploaded in the database, not in the file system? On Sep 8, 3:06 pm, Ludwig <[EMAIL PROTECTED]> wrote: > Is there a pressing need to do this? > > I think the design decision here was that serving image files to users is > something that web-servers will be able to do with much less overhead. > If you need to perform image manipulation on the fly, maybe have a look at > sorl.thumbnail (http://code.google.com/p/sorl-thumbnail/), which gives you a > lot of the power of the Python Imaging Library within a template tag, while > leaving your image data on the file-system. > > Ludwig > > 2008/9/8 nsash <[EMAIL PROTECTED]> > > > > > How can I upload an image in the database? As it is now , in database > > is saved only the path to it. > > The image itself is in the file system. > > > Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Upload images to rich-editor in admin interface
Nathan R. Yergler wrote: > I was working on this yesterday and have a working Django application > that supports most of the API. I'll be working on finishing it up > today, and will release it tomorrow or Tuesday, depending on when I get > things cleaned up. Anyway, that may make FCKeditor a good choice for > you. I'll announce it on django-users when its available. Well. Its a very good news. It is very most expecting feature for us Please inform me about any results because i am already thought to start own project --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Upload images to rich-editor in admin interface
FCKeditor has an XML API that can be implemented on the server side to support the upload/browse functionality for images, etc. (see http://fckeditor.wikiwikiweb.de/Developer's_Guide/Participating/Server_Side_Integration#Browser). I was working on this yesterday and have a working Django application that supports most of the API. I'll be working on finishing it up today, and will release it tomorrow or Tuesday, depending on when I get things cleaned up. Anyway, that may make FCKeditor a good choice for you. I'll announce it on django-users when its available. Nathan Scater wrote: > I have simple model: > class Entry(models.Model): > ... > body = models.TextField() > ... > > And i use rich-editor like TinyMCE or FCKEditor etc in admin-interface. > for edit a field "body" > I need functionality of uploading images for user's computer to this > editor directly. > I understand that decision depends on chosen editor and that i need > some server-side code. > > May be someone dials with this problem and have ready-made solution > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Upload images to rich-editor in admin interface
I have simple model: class Entry(models.Model): ... body = models.TextField() ... And i use rich-editor like TinyMCE or FCKEditor etc in admin-interface. for edit a field "body" I need functionality of uploading images for user's computer to this editor directly. I understand that decision depends on chosen editor and that i need some server-side code. May be someone dials with this problem and have ready-made solution --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---