Reputation: 2080
requests post:
requests.post('http://643f3392.ngrok.io/test_linux/', data={"jsondata": "here", "you_got":"data"})
I want to get data like this(views.py):
def get_data(request):
request.POST.get("data", None)
How to get {"jsondata": "here", "you_got":"data"} on django?
Upvotes: 0
Views: 470
Reputation: 81
def get_data(request, *args, **kwargs):
if request.method == "POST":
json_data = request.body
from rest_framework.decorators import api_view
@api_view(["POST"])
def get_data(request):
if request.method == "POST":
json_data = request.data
Upvotes: 0
Reputation: 984
def get_data(request):
if request.method == "POST":
payload = json.loads(
request.body.decode('utf-8'))
# Rest of your code
The variable payload
will be a dictionary.
In your case its value will be {"jsondata": "here", "you_got":"data"}
Upvotes: 1