Skip to content

Instantly share code, notes, and snippets.

@MariuszWisniewski
Created December 17, 2015 15:47
Show Gist options
  • Save MariuszWisniewski/8f52aab4462880ebda64 to your computer and use it in GitHub Desktop.
Save MariuszWisniewski/8f52aab4462880ebda64 to your computer and use it in GitHub Desktop.
Custom responses in CodeBoxes
#HTML response CodeBox
content = "<html>\
<head>\
</head>\
<body>\
<p>Welcome from Syncano Webhook!</p>\
<p><a href=\"https://www.syncano.io/\">Visit our website</a></p>\
<p>You're inside an instance named {instance}</p>\
<p>Watch \"Stop Building the Backend\" talk by our Developer Evangelist Kelly Andrews</p>\
<p><iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/zKLMc4ZoQJo\" frameborder=\"0\" allowfullscreen></iframe></p>\
</body>\
</html>".format(instance=META['instance']);
response = HttpResponse(status_code=200, content=content, content_type='text/html')
set_response(response)
# HTML Redirect response CodeBox
content = "<html>\
<head>\
<meta http-equiv=\"Refresh\" content=\"0; url=https://www.syncano.io/\" />\
</head>\
<body>\
<p>Please follow <a href=\"https://www.syncano.io/\">this link</a>.</p>\
</body>\
</html>"
redirectResponse = HttpResponse(status_code=302, content=content, content_type='text/html');
set_response(redirectResponse);
# JSON response CodeBox
import json
dictionary = {
"status" : "OK",
"message" : "Visit us",
"link" : "https://www.syncano.io"
}
content = json.dumps(dictionary)
redirectResponse = HttpResponse(status_code=200, content=content, content_type='text/json');
set_response(redirectResponse);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment