Sumit
How
Do I write form.save in async
Anonymous
are field and attribute are the same thing in serializer
Maxim
Sumit
How do I use async with if else statement ?
Anonymous
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
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
Anonymous
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?
Anonymous
Hamza
Hello
Hamza
I need post api to upload image from frontend
Hamza
Anyone can help me ?
Morteza
Руслан
🖐🏻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
Hamza
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?
Hamza
Hamza
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
Morteza
Hamza
"detail": "JSON parse error - 'utf-8' codec can't decode byte 0xff in position 265: invalid start byte"
Hamza
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
Hamza
Koen de
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
Hamza
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?
Chocolate_girl
Hamza
Koen de
And the networkpanel in your browser as I asked?
Hamza
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
Koen de
Koen de
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
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?
Gindera