Comments (4)
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.
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.
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.
@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)
- missing "database" folder
- Allow to send extra parameters in the POST request.
- Multiple submit buttons in modal
- Maintenance of the project HOT 9
- Automate JS Minify Process
- How to make a nested modal
- Undesired GET request when using a BSModalCreateView HOT 4
- Incorrect errorClass in documentation HOT 1
- Generic views don't respond to get_success_url() since version 3.0.0 HOT 5
- Delete view success message is shown although object not deleted HOT 1
- form validation object already exist error does not shown in modal after modal form submissin with crispy form within modal HOT 3
- Django Internal server error - widget_tweaks failed to parse render_field HOT 1
- Checkbox does not render correctly. HOT 3
- btnSubmit fails detection after html minification
- Double post when submitting modal form HOT 5
- Restrict users from directly accessing the form url HOT 1
- How to remove Click listener HOT 1
- Open a new modal with the current modal form's results
- Event listeners disappear after the form is invalid. HOT 1
- FormValidationMixin shadows setting of self.object (defined in BaseCreateView)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-bootstrap-modal-forms.