P
P
pvgdrk2015-06-22 21:22:47
JavaScript
pvgdrk, 2015-06-22 21:22:47

How to make django redirect on click?

The home page loads like this:

def main_page(request):
    c = {}
    c.update(csrf(request))
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/accounts/login')
    else:
        return render_to_response('homeTemplate.html',c)

This is when the client goes directly to the domain url.
And how to make this transition work on click? (it is assumed that the domain name is taken from the server, and not embedded in js or html):
$('#goHome').click(function(){
    //? ajax?
})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pvgdrk, 2015-06-27
@pvgdrk

everything was easier

$('#goHome').click(function(){
    window.location.replace('/');
})

url.py
(r'^$', main_page)

A
Artem Soshnikov, 2015-06-24
@artem90

I will not go into details why this is necessary, although it is still interesting.
You can make a new controller (for example, ajaxLinkController - it will drive all such links), in which to pass #goHome, and in response to an ajax request, receive json with the desired url, which you can follow later.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question