Hello Djangooos:
I am building a simple Django application, that shows products in items/employee_id url, the customer opens the link and start selecting the items by clicking on them, then an action button appears to prepare for submission to display a modal asking the customer to enter his data name, phone number location and email, then the customer either clicks on submit the order or cancel, if he clicks on submit the order button it will redirect to messenger chat page with order details where he can send the order which he selects, this popup window (handle_form_submission) asks the customer to either send the message or cancel sending, send the message button will open the Chat Page on The Agent chat page with a copy of the Order details and wait for the customer to send the order, the cancel will redirect the customer to the items/user_id url the same where he starts, if the user clicks on send the order, and then clicks on a back button from the browser it should redirect him also to the items/user_id url where he starts, to start a new order or close the page.
I have two issues as follows:
1- Cancel button in the popup redirect message doesn't redirect to the items/user_id url link, it redirects to the items/
2- After Sending the message, if clicks the back button on the browser it will take to the previous step which is the popup message, this back button should redirect to the items/user_id
The order cycle is as follows:
Selection > Prepare for submission > Submit the order > Send the message.
I use session in Django project to store the user_id.
I'd be glad to craft a solution that addresses the issues you've outlined:
Solutions:
1. Cancel Button Redirect Issue:
Code Example (assuming a Django form):
from django.shortcuts import redirect def handle_form_submission(request): if request.method == 'POST': form = YourForm(request.POST) if form.is_valid(): # Handle order submission logic (if applicable) if 'cancel' in request.POST: # Check for cancel button submission user_id = request.POST.get('user_id') # Get user_id from hidden field return redirect('items/{}'.format(user_id)) # Redirect with user_id # ... handle submit logic return render(request, 'your_template.html', {'form': form})
2. Back Button Redirect Issue:
Code Example:
from django.shortcuts import render, redirect def after_message_view(request): if request.session.get('order_submitted'): del request.session['order_submitted'] # Remove flag to avoid confusion later return redirect('items/{}'.format(request.session.get('user_id'))) # ... display normal page content return render(request, 'your_template.html')
Additional Considerations:
By implementing these solutions and considerations, you should be able to achieve the desired behavior for your Django application, ensuring that the cancel button and back button both redirect the user to the items/user_id URL as expected.
don't hesitate to ask further info.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/7mnPNB69lUU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a43d2c4d-e6b8-4a64-9f45-9a7d34bf5f54n%40googlegroups.com.