These are chat archives for django/django

4th
Sep 2018
Alexei Znamensky
@russoz
Sep 04 2018 00:26
@ryan-WORK It depends on how exactly you are using DRF in your project, but the bottomline is: you will need to override a method of some class. If you are using a view class, then:

"""
class ListUsers(APIView):
...
def post(self, request, args, *kwargs):
if validate(request):
return Response(process(request))
else:

        #return error

"""

not the formatting I expected, but I hope you see the point
If you are using ViewSets, you should do something like:
"""

"""
class MyViewSet(viewsets.ModelViewSet):
def create(self, request):
if validate(request):
return Response(process(request))
else:

        #return error

"""

Or something similar to that. Obviously these snippets are not test-proof, but you can find a very good tutorial in the DRF site, with a number of examples on how to use Views and Viewsets.
Alexei Znamensky
@russoz
Sep 04 2018 00:32
And last but not least, if you want to code just a validator and some other piece of code is going to perform the actual processing of the request - which is probably a good idea - AND if your validation procedure is the same across a number of different request-handlers, you might want to consider writing a Middleware, rather than a "POST" method
hope that helps.
Shashank Parekh
@sp1rs
Sep 04 2018 07:36
@ryan-WORK as per @russoz suggesstion his approach is also fine. or if you are validating the header in all the apis you can add the middleware or for more cleaner approach write a decorator.
Gaurav Paliwal
@paliwalgaurav
Sep 04 2018 09:45
Hello, I’m facing a problem while separating the frontend code from the django app.
I’m using django-alluth to maintain social authentication so at the time of separation I’m facing CORS issue sometimes preflight response, sometimes origin null issues. I tried to add origin in authentication app but still facing the issue.
Anyone please ?
Shashank Parekh
@sp1rs
Sep 04 2018 10:02
@paliwalgaurav Code snippet. Can’t say anything without code.
Gaurav Paliwal
@paliwalgaurav
Sep 04 2018 10:05
What code you wanna see?
Actually here it's not much to show because authentication side almost everything is handled by django-allauth. What I’m just trying to do is to hit the oAuth authentication api from frontend which is ok, but it returns me the CORS issues I’ve mentioned earlier/
Shashank Parekh
@sp1rs
Sep 04 2018 10:06
Add the middleware then, which will set Access-Control-Allow-Origin and Access-Control-Allow-Methods on every request/response.
Gaurav Paliwal
@paliwalgaurav
Sep 04 2018 10:08
added this, I used django-cors-headers for this and tried from the front end too
:]
@elcolie
Sep 04 2018 10:47
Hi
I have a problem with cors in the production
CSS is OK, but font is not
Fisher
@0fisher
Sep 04 2018 11:39
...
DikshitMaheshwari
@DikshitMaheshwari
Sep 04 2018 14:33
My css code is running well on local server but when I deploy it on pythonanywhere.com the changes in css are not getting deployed.
:]
@elcolie
Sep 04 2018 16:19
@z4nD4R Have you tried Two scoops of Django?
And https://www.codingforentrepreneurs.com/
You'd better start from here
It will clear out your questions and save your time
zandar
@z4nD4R
Sep 04 2018 16:20
@elcolie I know that page.. and not.. Im not trying to make 2 scoops of Django.. Im like trying to do smth like multitenancy
Ryan
@ryan-WORK
Sep 04 2018 18:20
@russoz & @sp1rs thanks so much I am working on the implementaion right now =).
Ryan
@ryan-WORK
Sep 04 2018 19:15

@russoz & @sp1rs I have one question about the process of saving the data that has ben generated by the validation process…

What are the commands that will allow me to group that data into the associated fields for the new model instance ?
Or is it not that simple?

Ryan
@ryan-WORK
Sep 04 2018 20:36

Actually I think I might have got it…

This is what I am working with LOL:
sample = DDataSerializer(data={'d':'{"a":2}’})
t = sample.is_valid()
print(sample)
print(t)
sample.save()

Using:
class DData(models.Model):
d = JSONField()

@russoz & @sp1rs