Reputation: 715
I have a form on a template on my domain1 and want to send a POST request to domain2. I am using Django as the framework. I only want domain2 to accept requests from domain1 and domain2 (itself). However, I run into csrf problems.
Upvotes: 0
Views: 2502
Reputation: 1206
You need a RESTful API. That's a very large topic and would be dumb/impossible to do the work for you here with the info I've been given, so here's a summary.
I suggest Django Rest Framework for making api's.
What the above means, is that when you want to do this sort of stuff (POST requests from other domains), you need a token. This is usually done with a Json Web Token. Also known as JWT's.
The process goes like this:
The data format for all this is USUALLY done with JSON. So you will have to import json, then json.dumps(obj)
to turn it into valid json, and json.loads(obj)
to turn your response into a python dictionary, so you can use it in your template, or wherever you want.
If you want to see an example of this, I recently made a free GoFundMe clone on my guthub. In the donate()
view at the bottom, it uses the requests library, and shows how a JWT is obtained and used. You can see it there.
Upvotes: 2