Django API status code 200 but data is not updating in Database - django

I am Using Django framework to create an Update-API. I have used Pymongo library, I am making a POST request from my react app using Axios, The response shows a status code of 200, but there is no change in the database.
Points to Note:
*The API works fine with POSTMAN.
*I have written the same API in flask which works well.
* I am working with other POST requests too in Django like /signup which works well.

Related

redirect_uri Parameter error on WeChat SSO on redirection of authentication url

I am implementing WeChat SSO for my web application, I have developer account, created an application there, followed this article exactly. I am using React on front-end and flask on backend.
I am using this package for flask for WeChat-sso.
So in my weChat dashboard I have registered official website e.g (chess.com), but I have to use callback url in such way so I can test redirection on my dev server.
My dev front-end is on (localhost:8000/)
My backend server is running on (127.0.0.1:5050/)
I have tried saving different callback urls e.g (127.0.0.1:5050/api/users/wechat/callback), no matter what I save in callback url always receiving parameter error.
So my question is how do I actually achieve this functionality locally? Instead of parameter error I should be seeing QR code so that I can get code from which I can get access_token. Following code generates authentication url
from weixin import WXAPPAPI
from weixin.lib.wxcrypt import WXBizDataCrypt
from weixin.client import WeixinAPI
scope = ("snsapi_login",)
api = WeixinAPI(appid=WECHAT_APP_ID,
app_secret=WECHAT_APP_SECRET,
redirect_uri=WECHAT_REDIRECT_URI)
authorize_url = api.get_authorize_url(scope=scope)
The authentication url generated is as follows, redirect URI is properly encoded just like in the documentation.
https://open.weixin.qq.com/connect/qrconnect?appid=wx35c78a124e8f027b&redirect_uri=127.0.0.1%3A5050%2Fapi%2Fusers%2Fwechat%2Fcallback&response_type=code&scope=snsapi_base&state=689db1f29605481a492639e98c7b1f9f#wechat_redirect
Please look at the picture of error as well thanks

Django JWT authentication doesn't work in browser?

I'm trying to do django authentication with JWT in my django+react app. I'm using part 1 of this tutorial: https://hackernoon.com/110percent-complete-jwt-authentication-with-django-and-react-2020-iejq34ta
Everything works fine when I use cURL in terminal to get access to my API, but when I run server in my browser I'm still getting
What does this behaviour mean?

Consume an API in Django REST, server side, and serve it ,client side, in Angular

I have an Angular app that consume API client side. Since it's bad practice to do so (I don't want to expose my API credentials), I decided to split into backend/ frontend before myapp get to big.
I succeed to implement my Angular into a Django REST framework app and everything is working fine.
But now I need to change my API logic and have DRF consume the external API
I had:
Angular <---API---> ext data
Now I have:
Django/ Angular <---API---> ext data
What I need:
Angular <---API---> Django <---API---> ext data
But I am very confused about how to accomplish it. I have experience with setting up API endpoints in DRF, but only for data from models within DRF. I know as well how to consume API in Django.
But how can I chain two API calls?
Do I have to create a model to store the queries and then the response?
Do I need to write serializers even if the returned data is json all the way?
How my frontend will now that the data from the external API is available?
What I need is someone to explain me what is the pattern for this task.
Say you have a FBV mapped to an URL in django like this:
url: /api/animals/<str:key>
#add_decorators_as_needed
def animals_view(request, key=None):
data = requests.get(f'{API_URL}/{key}?api_key={API_KEY}') # grab data from ext provider
json_data = ... # convert to json or do other manipulations
return json_data # return data to the frontend
Then in the frontend, your Angular app, you can execute a get request to this /api/animals/cow url of your django app and retrieve the data for a cow from the external provider without exposing your API_KEY.
So the flow would be like this:
Angular requests data from Django, Django gets that data from the external provider, does some data processing if required and then returns that data to Angular. You do not have to store anything in the database (but you can of course do it or for example log things, it's optional).

Is it secure to create API in Django without Rest Framework?

I've created an app in my Django project which works the same as API.
But for post requests, logins I'm doing something like this.
request "GET"(URL: example.com/api/get) this returns a csrftoken which is then used by my applications as a cookie.
request "POST"(URL: example.com/api/login), Here the frontend application logs in the user. The csrftoken from example.com/api/get is used in cookies and the same is used as csrfmiddlewaretoken in post data.
My question here is, it is secure to create an API like this and use it instead of Django RestFramework.
Any suggestion will be appreciated.THANK YOU

Django + REST_Framework - how can I get my app to POST serialized data to another HTTP server?

I have a Django app that is using REST_Framework and I can GET, POST, PUT, etc., to it as expected.
What I would like to do now, however, is automatically POST data from my Django app to another server.
Basically, I have a situation in which an asynchronous job runs, and when it is complete, rather than wait for the other server to poll my app for the latest updates, I want my app to just POST the data automatically.
I would like to continue using the REST_Framework serializers, etc.
You could just use python-requests do post your data (towards the end of your view function).
payload = serialized_object
request.post(url, data=payload)