2
votes

Is there a way to redirect a form POST to a specific page if the endpoint return a success ?

In my specific case, I'm using django-rest-auth to manage the users authentication, and the login endpoint (/rest-auth/login/) return a JSON with the response. I want to redirect the user to his dashboard if the authentication is successfull.

EDIT : As far as I understand, the REST api is only for backend. If I want to set a redirection after any form post, I have to find a way only with my frontend application. Am I right ?

In this case, is Django a good choice to develop the frontend application ? I've seen many subjects where AngularJS is mentionned to build the frontend. Is it a good idea to build a client app with JS (I mean, for a one page web api, there is no back and next navigation possibility, I think this is not a friendly way to navigate) ?

If I build my frontend with Django, do I have to write my own view, call the backend rest endpoint in this view, process the result, and send an HTTPRequest (for exemple) from this view ? I don't really understand where is the gain with this method.

2

2 Answers

1
votes

Well, answer to your question couldn't be only one solution.

You have two ways:

Everything depends on your needs.

1
votes

If I want to set a redirection after any form post, I have to find a way only with my frontend application. Am I right ?

Yes, you need to do the redirection on the front-end.

In this case, is Django a good choice to develop the frontend application ?

Django is a framework for building web servers, and it has nothing to do with front-end.

I mean, for a one page web api, there is no back and next navigation possibility, I think this is not a friendly way to navigate)

There is. For example, here is the ui-router for angularjs. Here is an example of an actual working page. As you can see, the url changes accordingly, just behaves like traditional server-rendered static html pages.

When the browser sends a request to your server, django calls the corresponding view function to render a view, which is just an html file, and sends it back to the browser. Then the browser renders the page. Beyond this point, django has nothing to do with the html file anymore. It is the browser's job to parse the html, and render it accordingly.

So, to be clear, django is not for front-end. For your web application, you can use angularjs for sure. However, if you don't really want to write a lot of javascript code, I suggest taking a look at Polymer (polymer-project.org, oh my little reputation), which is really easy to use.