Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
Django window.location not replacing string

I have a javascript function in a django view that is supposed to redirect the user to a different URL that contains a query parameter. When I print out the url before assigning it to window.location, it matches the url pattern as expected. However once I assign the URL to window.location, it seems to append the url to the already existing one instead of replacing it, and thus cannot find the matching url pattern.

Javascript function:

function downloadEvidence() {
    var product_review_ids = getProductReviewIDs();

    if (product_review_ids === '') {
        window.alert("Please select at least one deployment.")
        return;
    }

    var url = window.location.href + "download_evidence?productReviewIDs=" + product_review_ids
    console.log(url); //prints: http://127.0.0.1:8000/access-review-owner/configure/new%20test%20product/download_evidence?productReviewIDs=14

    window.location = url;
}

The url pattern it is supposed to match:

    urlpatterns = [
    path('access-review-owner/configure/<str:product_name>/download_evidence/',views.download_evidence_view, name='download_evidence_view'),

    ]

The view it's supposed to navigate to:

@require_http_methods(['GET'])
def download_evidence_view(request, product_name):
    product_id = request.GET.get('productReviewIDs', None)
    print(product_id)
    '''
    NOTE: Package up evidence here
    '''

    return HttpResponseRedirect(os.environ['BASE_URL']+f'access-review-owner/configure/{product_name}/download_evidence/')

The url it's attempting to find when I assign the correct one to window.location:

GET http://127.0.0.1:8000/access-review-owner/configure/new%20test%20product/download_evidence/access-review-owner/configure/new%20test%20product/download_evidence/
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try to add this code

function downloadEvidence() {
    var product_review_ids = getProductReviewIDs();
    var product_name = //try to get you product name

    if (product_review_ids === '') {
        window.alert("Please select at least one deployment.")
        return;
    }

    var url = `${window.location.origin}/${product_name}/download_evidence?productReviewIDs=${product_review_ids}`
    console.log(url); //prints: http://127.0.0.1:8000/access-review-owner/configure/new%20test%20product/download_evidence?productReviewIDs=14

    window.location.assign(url);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!