Sumit
How Do I write form.save in async
Anonymous
are field and attribute are the same thing in serializer
The Inspired
are field and attribute are the same thing in serializer
No.... field in general is the *type* of serializer... attribute is the additional options / properties that the serializer can take, such as null, unique, etc.
Sumit
How do I use async with if else statement ?
Anonymous
Hello everyone I want to create MicroService Project We have a gateway service that is supposed to receive CRUD methods and return a response with django rest framwork And we have a service users that performs the CRUD operation using django gRPC framework in the database Now I want to connect these two services with gRPC and I don't know how Thank you for your guidance
The Inspired
def validate(self, attrs) what is atrrs here
attrs are the attriutes that you would pass to that method
Anonymous
in the case validate method attrs is the data we passed to the serializer?
Anonymous
its predefined argument
The Inspired
yes
Anonymous
thanks
The Inspired
which field's data you want to validate
The Inspired
that field would be passed to the serializer
Anonymous
I think it's not in our hands to pass the field its takes all fields i have two field emails and pass e.g. OrderedDict([('email', 'pla@gmail.com'), ('password', 'pla')])
The Inspired
are you using Serializer or ModelSerializer?
Anonymous
serializer only
The Inspired
ah.. then in that case, you probably will have to manually pass the fields
The Inspired
and write the logic for validating only one field
Anonymous
def validate(self, attrs): try: user = User.objects.get(email=attrs.get('email')) except User.DoesNotExist: user = None
Anonymous
no i did not need to pass the field
The Inspired
huh?
The Inspired
wait...
The Inspired
is this validation of your model or your serializer?
Gindera
I have been in programming for over a year, I have the wrong foundation and cannot read documentation, work with classes, etc. What book would you recommend or what to do?
Gindera
For working on Django, channels, websockets and so one on python
Soroosh
Hi guys . Has anyone worked with Pycharm debugger? My debugger runs but does not work. Can anyone help me?
Doragonsureiyā
Hi guys . Has anyone worked with Pycharm debugger? My debugger runs but does not work. Can anyone help me?
Your question is not related to Django. If it's a Python related question go to @Python group, otherwise please move to @PythonOfftopic group and ask there.
Hamza
Hello
Hamza
I need post api to upload image from frontend
Hamza
Anyone can help me ?
Morteza
Anyone can help me ?
send with FormData
Hamza
send with FormData
Do you mean with postman ?
Morteza
Do you mean with postman ?
From which software you want to upload image? framework or application?
Руслан
🖐🏻hello Django == 1.10 and PostgreSQL After re-migration: python3 manage.py migrate I recieve "No migrations to apply" and this process takes +-5 minutes. Please tell me how can I reduce this time
Koen de
🖐🏻hello Django == 1.10 and PostgreSQL After re-migration: python3 manage.py migrate I recieve "No migrations to apply" and this process takes +-5 minutes. Please tell me how can I reduce this time
1.10 seriously? Please start upgrading. And.. to be honoust.. with only “this” information anything can be the issue or solution. What Python version. What PostgreSQL, what OS, what hardware, how big is your project (how many models, how many migrations are already available) …..
Koen de
application
How does (or can) that application call your image upload API? It is going to send the image as binary or base64 or URL?
Koen de
I don't know , I am beginner What is the best way ?
There is no best or worst way. How is the image “available” in your frontend? Please provide as much information as possible so we can help
Hamza
def uploadImage(request): import json print(request.data["invite_id"]) image = json.loads(request.FILES.get['image']) invite_id = json.loads(request.data['invite_id']) ivite_image = inviteMarried_request.objects.get(id=invite_id) ivite_image.image =image ivite_image.save() return Response('Image was uploaded')
Hamza
"detail": "JSON parse error - 'utf-8' codec can't decode byte 0xff in position 265: invalid start byte"
Morteza
You shouldn't use json.loads for image just get it directly
Hamza
i will try it now
Hamza
Same proplem
Koen de
You can help yourself by understanding what you upload; just before “import json” set; import pdb pdb.set_trace() Then check what’s inside “request”
Hamza
def uploadImage(request): image = request.FILES.get['image'] invite_id = request.data['invite_id']) invite_image = inviteMarried_request.objects.get(id=invite_id) invite_image.image =image invite_image.save() return Response('Image was uploaded')
Hamza
i try this
Koen de
What should I put in this terminal
Just “request”. (Without the “”)
Koen de
Just “request”. (Without the “”)
Then you will see what request is all about. You can also see what’s inside “request.FILES”
Hamza
Ok thank you
Hamza
It returns this
Hamza
With request.data
Hamza
rest_framework.exceptions.ParseError: JSON parse error - 'utf-8' codec can't decode byte 0xff in position 265: invalid start byte
Koen de
What should I put in this terminal
This pdb (Python DeBugger) is pretty handy. Just like the “dir()” method. See https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/functions.html#dir
Koen de
rest_framework.exceptions.ParseError: JSON parse error - 'utf-8' codec can't decode byte 0xff in position 265: invalid start byte
Okay , and just “request”? The error suggests you are trying to read JSON , but are not sending JSON. Can you check the networkpanel of your browser too, to verify what you are actually sending to the API?
Koen de
Does “def uploadImage” have any decorators? And/or how does your urls.py look like. Is the method “uploadImage” inside a ViewSet or just a standalone method?
Koen de
And the networkpanel in your browser as I asked?
Koen de
I don't understand 🥺
Can you check the networkpanel in your browser to see what data you are posting to the server? The networkpanel in Chrome/Firefox is in the Developer tools (mostly with key F12)
Mohammed
Hi friends. I am a beginner to django. I have created a one page website in that i have contact form and i am getting the data in admin side. Now i wish to add a alert when ever user successfully submit the form. I am not using builtin forms. I wish to know how i can check whether the form is empty or not during the form submission.
Koen de
Hi friends. I am a beginner to django. I have created a one page website in that i have contact form and i am getting the data in admin side. Now i wish to add a alert when ever user successfully submit the form. I am not using builtin forms. I wish to know how i can check whether the form is empty or not during the form submission.
Both can be found in the documentation; For the first question, check Django Signals ; https://docs.djangoproject.com/en/4.1/topics/signals/ For the second see Form Validation; https://docs.djangoproject.com/en/4.1/ref/forms/validation/
The Inspired
serializer
then why are you invoking the model inside your validation? serializers will only the incoming data... once the data is validated, then only the data passes on to thr model.
Koen de
For working on Django, channels, websockets and so one on python
The book “Two scoops of Django” helped me to start with Django in the first place. There is a Django 3.x edition. Another good one is “Lightweight Django (o’reilly)”, but it is not really up to date anymore. Same with “Practical Django 2 and Channels 2 (apress)” For Python, not really for beginners, but “Fluent Python (o’reilly)” is pretty good too.
Andrey
hi all, do someone know how write django unit tests for celery tasks? there is a some problems with running this task with delay
Doragonsureiyā
hi all, do someone know how write django unit tests for celery tasks? there is a some problems with running this task with delay
Your question is not related to Django. If it's a Python related question go to @Python group, otherwise please move to @PythonOfftopic group and ask there.
Krunal
Hi Guys, I want to implement jwt authentication with drf. I have a legacy database. I have tried djangorestframework-simplejwt but it's use the default user module. Can someone help me?