Is it an error by Django?

47 views
Skip to first unread message

utpalbr...@gmail.com

unread,
Oct 5, 2017, 12:45:38 PM10/5/17
to Django users
The below code looks wierd.
   def __init__(self, content=b'', *args, **kwargs):
        super(HttpResponse, self).__init__(*args, **kwargs)
        # Content is a bytestring. See the `content` property methods.
        self.content = content
The wierd part is /// content=b''///

Lachlan Musicman

unread,
Oct 5, 2017, 6:36:38 PM10/5/17
to django...@googlegroups.com
I'd imagine that's the new Python3 system. content is a bytestring, not unicode?

Cheers
L.

------
"The antidote to apocalypticism is apocalyptic civics. Apocalyptic civics is the insistence that we cannot ignore the truth, nor should we panic about it. It is a shared consciousness that our institutions have failed and our ecosystem is collapsing, yet we are still here — and we are creative agents who can shape our destinies. Apocalyptic civics is the conviction that the only way out is through, and the only way through is together. "

Greg Bloom @greggish https://twitter.com/greggish/status/873177525903609857

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/02a0b8a6-e4b9-4d68-bc94-1fde59f60f08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lachlan Musicman

unread,
Oct 5, 2017, 6:43:14 PM10/5/17
to django...@googlegroups.com
Yeah, if you look in the docs here
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals

"Bytes literals are always prefixed with 'b' or 'B'; they produce an instance of the bytes type instead of the str type. They may only contain ASCII characters; bytes with a numeric value of 128 or greater must be expressed with escapes."


and the bytes link shows

https://docs.python.org/3/library/stdtypes.html#bytes

cheers
L.


------
"The antidote to apocalypticism is apocalyptic civics. Apocalyptic civics is the insistence that we cannot ignore the truth, nor should we panic about it. It is a shared consciousness that our institutions have failed and our ecosystem is collapsing, yet we are still here — and we are creative agents who can shape our destinies. Apocalyptic civics is the conviction that the only way out is through, and the only way through is together. "

Greg Bloom @greggish https://twitter.com/greggish/status/873177525903609857

utpalbr...@gmail.com

unread,
Oct 6, 2017, 6:51:03 AM10/6/17
to Django users

Well Lachlan Thank you very much.....

utpalbr...@gmail.com

unread,
Oct 6, 2017, 6:57:25 AM10/6/17
to Django users
I have a doubt....

As per your given link i guess it should be like ////    content=' b '    ////

Andréas Kühne

unread,
Oct 6, 2017, 7:33:15 AM10/6/17
to django...@googlegroups.com
Hi,

No, the correct format is  //// content=b'' //// otherwise you would just be default content to a string that equals "b". It says that there is no encoding on the string afterwards and it is a byte string. It works the same way Python 2 used to do with unicode strings, in that case it was //// content=u'' ////

Regards,

Andréas

2017-10-06 12:57 GMT+02:00 <utpalbr...@gmail.com>:
I have a doubt....

As per your given link i guess it should be like ////    content=' b '    ////

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

utpalbr...@gmail.com

unread,
Oct 14, 2017, 5:38:06 AM10/14/17
to Django users
Thank you Andréas Kühne

Reply all
Reply to author
Forward
0 new messages