Last active
July 9, 2022 10:54
-
-
Save dubeyji10/54b9419c5d94f704c1329ebeab3a00b3 to your computer and use it in GitHub Desktop.
second method to render api response - browser site resulting in error
This file contains hidden or 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
{% extends "main/base_templates/base.html" %} | |
{% block content %} | |
{% if result %} | |
----- call api with ----- | |
{{ message }} | |
{% else %} | |
<div> enter your details here </div> | |
{% endif %} | |
<form target="_blank" action = "" method = "POST"> | |
{% csrf_token %} | |
<label for="startDate">Start Date: </label> | |
<input id="startDate" type="date" name="startDate"> | |
<br> | |
<label for="endDate">End Date: </label> | |
<input id="endDate" type="date" name="endDate"><br> | |
<input type="submit" value="OK"> | |
</form> | |
{% endblock content%} |
This file contains hidden or 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
{% extends "main/base_templates/base.html" %} {% block content %} | |
<div> | |
{% if message %} | |
----- call api with ----- | |
{{ message }} | |
{% else %} | |
<div> enter your details here </div> | |
{% endif %} | |
</div> | |
{% endblock content%} |
This file contains hidden or 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
def credentials(): | |
print("sending tokens") | |
''' | |
to get access tokens from json file | |
refresh it to get working tokens | |
''' | |
mycredentialJson = None | |
with open(dir_path+"/"+'gotomeeting/refresh_tokens.json' , 'r') as f: | |
mycredentialJson = json.load(f) | |
# print("sending credentials : ",mycredentialJson) | |
return mycredentialJson | |
def getMeetingData(request): | |
myTokens = credentials() | |
print("....sending a", type(myTokens)) | |
return render(request,"getdata/meetingData.html",{'title':'meeting-data', | |
'message':'create a form to enter data and render data', | |
'myJsonTokens':myTokens['access_token']}) | |
# writing a custom view to handle form input and display at the same time | |
# example from https://www.digitalocean.com/community/tutorials/how-to-build-a-weather-app-in-django | |
#example date pattern -- | |
# startDate = "2022-05-01T12:00:00Z" | |
def meetingFormView(request): | |
# print('1->',request.POST) | |
# print('2->',request.POST.mycity) | |
if request.method=='POST': | |
print('here') | |
print('1->',request.POST) | |
startDate = request.POST['startDate'] | |
endDate = request.POST['endDate'] | |
print('2->',request.POST['startDate']) | |
print('3->',request.POST['endDate']) | |
result = { | |
'message' : "getting meetings between {} and {}".format( ''.join([str(startDate),'T12:00:00Z']), ''.join([str(endDate),'T12:00:00Z'])) | |
} | |
print('4-> result : ',result) | |
return render(request, 'getdata/meetingList.html',result) #returns the index.html template | |
return render(request, 'getdata/MeetingForm.html') #returns the index.html template |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment