Giter Club home page Giter Club logo

Comments (4)

bastiaan85 avatar bastiaan85 commented on June 28, 2024

Using this SO answer I was able to work around the issue by including a hidden form element with name="next" to provide the redirect url to the LoginView:

{% load widget_tweaks %}

<form method="post" action="">
  {% csrf_token %}
  <input type="hidden" name="next" value="{% url 'appname:index' %}">
  <div class="modal-header">
    <h3 class="modal-title">Log in</h3>
   [...]

from django-bootstrap-modal-forms.

trco avatar trco commented on June 28, 2024

The redirection really happens based on the LOGIN_REDIRECT_URL = '/' in the settings.py and success_url doesn't have an effect. Good catch. And at the same time good hack with the hidden input field and name="next". Regarding the successURL from .js, it was deprecated during implementation of Django messages.

I think that hidden input field and name="next" could provide some extra functionality for the package. Maybe I give it a shoot in the future.

from django-bootstrap-modal-forms.

bastiaan85 avatar bastiaan85 commented on June 28, 2024

To give my background story here: the reason I ran into this issue is that I want a redirect specifically to the index of the app the user was logging in at, so not the root of the project, meaning a global setting won't help me.

On a more general note I would expect it to default to the current page the user clicked the Log in button, like how most websites behave. Although most of them use an intermediate page, like Github here or Amazon for example, they then redirect to the previous page, not the root index.

Checking the Django docs on LoginView it seems that the class property extra_context is targeted to forward data to the template:

extra_context: A dictionary of context data that will be added to the default context data passed to the template.

And indeed providing success_url via that dict in the LoginView

class CustomLoginView(LoginAjaxMixin, SuccessMessageMixin, LoginView):
    authentication_form = CustomAuthenticationForm
    template_name = 'myappname/login.html'
    success_message = 'Success: You were successfully logged in.'
    extra_context = dict(success_url=reverse_lazy('myappname:index'))

and using success_url manually as the hidden form element's value

<input type="hidden" name="next" value="{{ success_url }}">

Works fine, so at least in that way the redirection value can be statically defined in the view again.

from django-bootstrap-modal-forms.

trco avatar trco commented on June 28, 2024

@bastiaan85 That's great way for custom success_url. I'll update the README.rst. Thanks for great contribution.

from django-bootstrap-modal-forms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.