Django Ajax success отправляет контекст в новый url

У меня есть первая страница с кнопкой Launch, процесс выполнен и все они перенаправляются на страницу результатов, где я могу загрузить различные результаты. Без Ajax и с "обычным" Django, процесс работает. Однако из-за других функциональных возможностей на первой странице мне приходится работать с Ajax. И если я не переформулирую успешную часть Ajax, ничего не происходит...

У меня есть представление функции для первой страницы :

def launchCtd(request):
"""
This Function is activate when user click on the launch button of the convertToDose page.
It receive the request, create the JSON file and launch the ConvertToDose Analysis. Then it redirect to the Result page
"""

if request.method == 'POST':

    #DO stuff
    context = {
        'filename': img_out_path,
        'protocol_file': json_pactrlRectth,
    }

    #return render(request, 'result.html', context)
    return JsonResponse(context, safe=False)# I trie to pass the url but it was not a success...

else:
    #Ini Forms
    context = {
        #Send Forms
    }
    return render(request, 'template.html', context)

шаблон первой страницы (только ajax часть)

$.ajax({
url: "",
type: "POST",
data: formData,
processData: false,
contentType: false,
beforeSend: function (xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", $('input[name="csrfmiddlewaretoken"]').val());
},
success: function(data){
    //print okay with JSONResponse in view
    console.log(data.protocol_file)
    
    //First try to send data in new url => undefined element, after = I tried with data and with template data in the 1st page
    //protocol_file = $("input[name='json_path']")
    //filename = $("input[name='img_path']")
    
    //Second try to send data in new url => undefined
    $('#protocol_file').html(data.protocol_file);
    $('#filename').html(data.filename);
    
    //Third try => GetElementById is undifined error 
    //document.GetElementById("protocol_file").innerHTML = $("input[name='json_path']")
    //document.GetElementById("filename").innerHTML = $("input[name='img_path']")
    
    //Fourth try => synthaxe error, I also tried with a + like in some forum but it consider like a str and concat all...
    window.location.href="/filmchromique/result/" {data:data}
    
    #this one is working but with no data sended .... 
    //window.location.href="/filmchromique/result/"
},
error: function (data, textStatus, jqXHR) {
    console.log(data)
}

});

Вид страницы результата :

class displayResultPage(TemplateView):
template_name = 'result.html'
def post(self, request, *args, **kwargs):
    self.object = self.get_object()
    context = self.get_context_data(object=self.object)
    return self.render_to_response(context)

def get_context_data(self, **kwargs):
    kwargs = super(displayResultPage, self).get_context_data(**kwargs)
    return kwargs

def post(self, request, *args, **kwargs):
    context = self.get_context_data(**kwargs)
    bar = self.request.POST.get('foo', None)
    if bar: self.template_name = 'result.html'

    return self.render_to_response(context)

В моем результате шаблона у меня нет ничего особенного, только, возможно, эта часть может быть интересной :

<div style="padding-bottom: 30%" class="row gx-5 justify-content-center">
{% if protocol_file is not null %}
    <p id="protocol_file">Your file is here : {{ filename }}</p>
{% else %}
    <h1 style="color: indianred">You must launch an analysis before accessing an image on this page</h1>
{% endif %}
{% if protocol_file is not null %}
<div class="row gx-5 justify-content-center">
    <div class="col-lg-4 col-xl-6">
        <a class="btn btn-primary btn-md" href="{% url 'json:downloadFile' protocol_file %}">Save protocol to local</a>
    </div>
<br>
    <div class="col-lg-4 col-xl-6">
        <a class="btn btn-primary btn-md" href="{% url 'json:downloadFile' filename %}">Save image to local</a>
    </div>
<br>
</div>

Я не нахожу способа отправить контекст. Если у вас есть идеи, как я могу это сделать, пожалуйста

Удачного дня

Вернуться на верх