Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8098377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:03:51+00:00 2026-06-05T22:03:51+00:00

the question: How do i redirect to a page in django but "fake" it

  • 0

the question: How do i redirect to a page in django but "fake" it as an ajax request?

So i have a post data request – done via ajax (jQuery). This gets sent to my django server, which adds the data (or removes it!) and then responds with a "well done you added some data" page.

This success page begins with:

{% extends request.is_ajax|yesno:"base_ajax.htm,base.htm" %}

which is a nice way of adding in all sorts of headers if the request wasn’t an ajax one, and ignoring the headers if it was. I added this so the site works both with and without javascript (do we need to do that anymore?)

And then i added a post-redirect-get (that is, the post part of the view doesn’t return render_to_response but rather return redirect('url here')

And now the problem is that the redirect forgets that the initial request was an ajax one. So i always end up loading the entire page – headers and all – into a div, which isn’t what i want.

So, i’d like to be able to tell the redirect that it should pretend to be an ajax request

How do i do that?

UPDATE: to anybody reading this in "the future (with jetpacks!)" redirects don’t carry the header information over – see https://www.rfc-editor.org/rfc/rfc2616#section-7.1

in the end, i went and did this:

return redirect(self.success_redirect + '/' + str(int(request.is_ajax()))) 

and then, for the view that i redirected to i had:

url(r'^editStorySuccess/(?P<ajax>\d+)$',
    showAfterCheckingAjax,
    {
        'template':'stories/editStorySuccess.html'
    },
    'editStorySuccess'
),

and in the showAfterCheckingAjax view i just had:

if int(ajax):
    request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
return render_to_response(template, {'user':request.user}, 
    context_instance=RequestContext(request))

and that works for me!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:03:53+00:00Added an answer on June 5, 2026 at 10:03 pm

    Create a different URL that presents the same view as the URL you’re redirecting to now but with an additional GET parameter. You can use this GET parameter to modify the template that is being used to serve the view. Either way, a redirect is considered a new request so you have to do something to pass this additional information to this request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a similar, but different, question like How to redirect Powershell output from
can I have a question about how to redirect the page after user invite
I want to $this->Session->setFlash('text'); $this->redirect('page'); but the message is not displayed. I have included
I posted a question earlier about why django redirect was not working correctly, but
I have a simple question, below My JS function is to redirect the page
This question is related to my other question How to redirect to Login page
I am new to python and django and i have a question regarding the
you can find a similar question here PHP Post Request inside a POST Request
Using django-multilingual and localeurl. Small sample of my main page view: def main(request): #View
Net application and from one page i have to redirect to silverlight page, i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.