These are chat archives for django/django

5th
Sep 2018
:]
@elcolie
Sep 05 2018 03:18
@z4nD4R Multitenancy is not related to your question at all. You have no basic and coding style of Django itself. Then resources I gave is a good start.
Good luck if you think you can handle it yourself.
Miracle Ayodele
@iammiracle
Sep 05 2018 06:08
i really need some help on django and tweepy, i want to pass streaming tweets to django context so i can use it on the template
Ryan
@ryan-WORK
Sep 05 2018 06:20

Thanks @russoz & @sp1rs!

Also do you have any opinions on the integration of Kubernetes with the Django App? It kinda goes past 2 scoops of Django LOL

@iammiracle

Could you please be a bit more specific?

Are you attempting to stream data VIA websockets or are we just attempting to go with a REST API call?

Miracle Ayodele
@iammiracle
Sep 05 2018 06:28
@ryan-WORK presently i am streaming data through REST API call
Ryan
@ryan-WORK
Sep 05 2018 06:33
@iammiracle
Do you mind if I ask, are the requirements to use tweepy for your twitter application?
Or could you be ok with using https://github.com/michaelbrooks/django-twitter-stream#settings ?
Django Twitter Stream
Miracle Ayodele
@iammiracle
Sep 05 2018 06:38
you mean is it compulsory for me to use tweepy?
@ryan-WORK
No, i am open to anything that works fine and nice support
Ryan
@ryan-WORK
Sep 05 2018 06:40
I have use the Django Twitter Stream from the link before, the docs are AMAZING and as I remember it was easy to use.
Alexei Znamensky
@russoz
Sep 05 2018 06:47
hi @ryan-WORK django+kubernetes: still on the to-do list
prinxy
@prinxy
Sep 05 2018 14:15

Django views

def account_view(request):
    """
    this renders the view of a user account, which contains all of users informations
    """
    long= request.user.long.all()
    short= CustomUser.objects.exclude(id__in=long).all()
    data = {
        "long": list(
            short.values(
                "first_name",
                "last_name",
                "username",
                "email",
                "pk",
            )
        ),
        "short": list (
            short.values(
                "first_name",
                "last_name",
                "username",
                "email",
                "pk",
            )
        )
    }
    return JsonResponse( data )

#

XMLHttpRequest ( javascript from client )

{
    let xhr = new XMLHttpRequest();
    xhr.open("GET", "http://localhost:8000/account/", true );
    xhr.onload = function () {
        if (this.status == 200 ) {
            console.log( this.responseText );
        }
    }


    xhr.send( )
}

Hello all, please i have this django view that's rendering queryset as json to client. and i'm using that javascript XMLHttpRequest request to retrieved what was sent from view.
When i use google chrome ( Version 68.0.3440.106 (Official Build) (64-bit) ) : i get the data sent from my django view.
When i use firefox quantum ( Version 61.0.2 (64-bit) ) i get this error Content Security Policy: The page’s settings blocked the loading of a resource at http://localhost:8000/account/ (“default-src”).

please guys i need your help on this....

i have done my research on this, and i what i found was all about CORS. i changed allowed_host in settings.py to * but still getting same error
prinxy
@prinxy
Sep 05 2018 15:09

please guys i actually need your help...

I tried something else

i tried sending my response as Http
return HttpResponse ( data )
and i tried retrieving the data using same procedure ( XMLHttpRequest ) in both browsers. Doing that i was able to get the actual data key...
instead of result to be queryset turned into json, i was getting just the keys. which are long short...

i just added content type as a second parameter with the value of "application/json"
that also didn't help

Thanks all, i've now gotten desired result

prinxy
@prinxy
Sep 05 2018 15:14
from django.core import serializers

long= request.user.long.all()
short= CustomUser.objects.exclude(id__in=long).all()


serialized_long = serializers.serialize('json', long)
serialized_short = serializers.serialize('json', short)
    return HttpResponse( [serialized_long, serialized_short], content_type="application/javascript")
this code sorted it out

Though i've gotten desired result, i will appreciate so well if anyone knows what was wrong with my first implementation ( which gave me desired result on google chrome but not on firefox )

AlejandroMendez
@AlejandroMendez
Sep 05 2018 15:46
Hello, somebody that knows a way to remove a label from a built in form such as PasswordResetForm without override the form?
prinxy
@prinxy
Sep 05 2018 16:00
@AlejandroMendez i implemented something of such, but mine wasn't password reset form but was user creation form
the way i did mine was to
-- import UserCreationForm
-- create a form called CustomUserCreationForm ( UserCreationForm ) ---------> i subclass the builtin form
-- i added a meta class within CustomUserCreationForm like this class Meta(UserCreationForm.meta )
-- then i did a dictionary of labels = {"fieldname" : '' }
AlejandroMendez
@AlejandroMendez
Sep 05 2018 16:01
:o thank you so much @prinxy for the quick response :)
prinxy
@prinxy
Sep 05 2018 16:01
i guess that same method should work for PasswordResetForm
AlejandroMendez
@AlejandroMendez
Sep 05 2018 16:01
but i've already solve the problem, with this:
image.png
prinxy
@prinxy
Sep 05 2018 16:02
great
AlejandroMendez
@AlejandroMendez
Sep 05 2018 16:03
in urls.py, the important part is:
PasswordResetForm(auto_id=False)
prinxy
@prinxy
Sep 05 2018 16:04
what does auto_id mean @AlejandroMendez
have a link to any article ?
AlejandroMendez
@AlejandroMendez
Sep 05 2018 16:05
check this
prinxy
@prinxy
Sep 05 2018 16:05
like how does it help to remove a label from a built in form such as PasswordResetForm
the part that says "If auto_id is False, then the form output will not include <label> tags nor id attributes:"
prinxy
@prinxy
Sep 05 2018 16:06
oooo... great
:+1:
AlejandroMendez
@AlejandroMendez
Sep 05 2018 16:07
anyway, thankyou so much for the response, i'm glad for found a site like these where there are people like you giving help!
prinxy
@prinxy
Sep 05 2018 16:12
@AlejandroMendez you are highly welcome... this is a community that help each other. In one way or the other, i learnt something new from your question... Whenever i get the chance to answer to what i've done b4, i do take the chances. For it's either i learn a better way to do what i already know how to do or learn something new while trying to help out. #### Happy Coding @AlejandroMendez
AlejandroMendez
@AlejandroMendez
Sep 05 2018 16:58
Happy Coding!