I am using FullCallendar (a node package) to display a calendar, I want to display data of an event in this calendar upon clicking it, which is handled by the following function:
eventClick: function(info) {
$.ajax({
type: 'GET',
url: 'get_lesson_by_id/',
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
data: {
current_id: info.event.id
},
success: function (res) {
$("#signupModal").modal('show');
}
})
}
This sends a request to my view where I want to update the context:
def get_lesson_by_id(request):
lesson_id = request.GET['current_id']
lesson = get_object_or_404(Lesson, pk=lesson_id)
print(lesson.to_dict())
return render(request, 'agenda/agenda.html', lesson.to_dict())
This all works great, an example of what the view prints is this:
{'lesson_id': 2, 'lesson_title': 'Vioolbouwweek', 'lesson_begin_date': datetime.date(2022, 6, 3), 'lesson_end_date': datetime.date(2022, 6, 9), 'lesson_begin_time': datetime.time(9, 0), 'lesson_end_time': datetime.time(19, 0), 'lesson_description': 'Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Morbi lobortis neque vitae tempus ullamcorper. Ut ac dolor euismod, congue tortor eu, suscipit nunc.
Fusce vulputate diam condimentum sem interdum fringilla. Suspendisse vitae justo vulputate, laoreet lacus quis, mattis lectus. Mauris tincidunt sit amet velit vel ultrices. Quisque tincidunt enim eu viverra dictum. Duis malesuada hendrerit ante nec commodo. Mauris condimentum, mi id gravida pretium, ante ex mollis leo, eu elementum orci lorem molestie neque.', 'lesson_type_name': 'Vioolbouwweek', 'lesson_duration_days': 7, 'lesson_teachers': ['Rob Stemerding']}
However when I try to use these new context variables in the template like so:
{{ lesson_id }}
they all show absolutely nothing.
I tried looking at the {% debug %}
and the context variables show up like so:
<Var token: "lesson_title...">, <Text token: " ...">] plural=[]>, <TextNode: '\n </h3>\n '>, <Variable Node: lesson_id>, <TextNode: '\n '>, <Variable Node: lesson_teachers>, <TextNode: '\n </div>\n <'> etc...
Buy I think this is just information as to where I am trying to use the tag.
CodePudding user response:
Now that I'm coffeed up, let me take another shot at this. So, it appears that you are sending over the template to be rendered, but in your success function, you never actually do anything with it. All you do is pop open the modal.
you need to so something like $("#whatever div is").html(res) then pop open the modal
Check out number 14 on this answer: Bootstrap 3 - How to load content in modal body via AJAX?