0

I have followed the code here https://learn.microsoft.com/en-us/outlook/rest/python-tutorialnd and it works however I need to access the calender events for my own purpose.

    context = { 'events': events['value'] }

return render(request, 'tutorial/events.html', context)

The HTML is

<table class="table">
  <tr>
    <th>Subject</th>
    <th>Start</th>
    <th>End</th>
  </tr>

  {% for event in events %}
    <tr>
      <td>{{ event.subject }}</td>
      <td>{{ event.start.dateTime }} ({{ event.start.timeZone }})</td>
      <td>{{ event.end.dateTime }} ({{ event.end.timeZone }})</td>
    </tr>
  {% endfor %}
</table>

My question is how can I interrogate context to obtain the data in the format shown above? Ie subject start date time and end date time.

I'm very new to Python.

I've seen how the data is held using debug statements.

See above

I need interrogate context to obtain the data in the format shown above? Ie subject start date time and end date time.

The data in Context looks like this

context data

How does the data get interpreted by the HTML?

Ken
  • 11
  • 4
  • 1
    Although I don't know exactly what's inside `events` variable I believe you shouldn't being passing just `events['value']` but the whole object like `'events': events`. The HTML looks fine – Higor Rossato May 31 '19 at 09:05
  • 1
    I'm not sure what your question is. Your code is exactly like the tutorial; what is wrong? What do you mean by "interrogate context"? – Daniel Roseman May 31 '19 at 10:10
  • Possible duplicate of [Django template how to look up a dictionary value with a variable](https://stackoverflow.com/questions/8000022/django-template-how-to-look-up-a-dictionary-value-with-a-variable) – martbln May 31 '19 at 11:03
  • I want to take the data from the Outlook calendar and use it to update a spreadsheet so I need to use the data that is formatted in context, immediately before the HTML layout. – Ken May 31 '19 at 13:10
  • More info: There are 3 items in the dictionary. The 3rd, value, contains the data that I'm interested in. I cannot work out how the HTML extracts the data. – Ken Jun 01 '19 at 14:49
  • Your question is _still_ not clear - is something not working as you expect ? If yes edit your post to explain what (with all relevant informations). Else, please rephrase your question more clearly. – bruno desthuilliers Jun 03 '19 at 09:25
  • As a side note: it's not "the HTML" that "interprets" the data, it's the Django template engine (which usage is extensively documented...) – bruno desthuilliers Jun 03 '19 at 09:27

1 Answers1

0

From understanding the code above, events['value'] seems like a list of dictionaries. In the python code, you should be able to access it using

for inner_dict in events['value']:
    print(inner_dict["subject"])
    print(inner_dict["start"]["dateTime"])
    print("*****")

The HTML code perhaps interprets it using Template Engine what does {% %} mean in html

Speeeddy
  • 154
  • 8