1

I know this should be csrf problem. But it works differently on different port.

The Django server is on 8000 and then I test the front end on both 3000 and 8000, I got:

When I test front end on localhost:3000, I can get the post work;

When I test front end on localhost:8000, I get 403;

$.post("http://localhost:8000/todos/", {title:this.refs.title.value,text:this.refs.text.value });

Any ideas how it works?

Shukai Ni
  • 457
  • 2
  • 6
  • 17

1 Answers1

0

Since you are reporting a 403 Forbidden, I would presume you're actually having a CORS issue, not csrf.

I'd recommend installing django-cors-headers and whitelisting your frontend on port 8000 in the settings.

A. J. Parr
  • 7,731
  • 2
  • 31
  • 46