0

I am running a Django project with react redux (trying to implement authentication system) and the very weird thing i observed that my site is rendering properly when i use localhost:8000 or http://127.0.0.1:8000.

But when i m trying to login/signup (ie trying to send post request) then it working only when i use localhost:8000, and giving some error when using http://127.0.0.1:8000.
One of the error when using http://127.0.0.1:8000 is shown below. enter image description here
However i have seen this and found localhost will often resolve to ::1, the IPv6 loopback address. But i am getting is it related to this or not ?
And whether localhost:8000 and http://127.0.0.1:8000 is same or not ?
Please try to answer in simple words because I have not much knowledge of internet protocol or networking.

Abhishek Pratap Singh
  • 613
  • 3
  • 11
  • 18
  • For the difference between localhost and 127.0.0.1 please refer to https://stackoverflow.com/questions/7382602/what-is-the-difference-between-127-0-0-1-and-localhost – Prateek Chaudhary Aug 29 '20 at 21:40
  • As far as the CORS protocol goes, the difference is simply that the strings `http://127.0.0.1:8000` and `http://localhost:8000` don’t exactly match, character for character. When comparing two origins, the CORS protocol requires browsers to essentially do a simple character-for-character exact string match. There’s nothing in CORS for recognizing `127.0.0.1` and `localhost` as the same; instead for CORS purposes, those are seen as completely different strings of characters. For CORS purposes, in order to be considered same-origin, they need to exactly match each other, character for character. – sideshowbarker Aug 29 '20 at 21:52

1 Answers1

0

This problem is because of CORS. You have to enable from outside your application.

This happens because django apps and generally all frameworks blocks requests outside your address.

You can read more about CORS here

carlosza
  • 365
  • 2
  • 9
  • i am making request from localhost to localhost then how it is outside request? And why Django is blocking this? And the other thing is Does enabling CORS, will not make my authentication system vulnerable? Because generally we all are logged in our browser, and if i will not block outside request then some phising website can indirectly send requests to delete the user. – Abhishek Pratap Singh Aug 29 '20 at 21:50