Created
August 30, 2023 12:37
-
-
Save develhopper/73045712b394c2c2439d5e97ac4dbf1b to your computer and use it in GitHub Desktop.
Django response helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.response import Response | |
def success(message,data=None,status=200): | |
result = { | |
"message":message, | |
"result":data | |
} | |
if page: | |
result['page'] = page | |
return Response(result,status) | |
def fail(message,status=400,data=None): | |
result = { | |
"message":message, | |
"result":data | |
} | |
return Response(result,status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from utils.response import success,fail | |
def get_post(requests): | |
id = request.data.get('id',None) | |
post = Posts.object.filter(id=id).first() | |
if not post: | |
return fail("Post not found",404) | |
return success("Message",posts) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment