Mauro Caresimo
2018-11-05 11:03:35 UTC
Hello Im having some issues trying to pass an id through a modal. Basically
I want to pass an id through a modal, via urls.py and to hit a function in
the views to delete the user.
This is my modal:
Much appreciated for any help. Fairly new to Django. Really hope someone
can come to my rescue :-)
<!-- BEGIN CONFIRM MODAL -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">{% trans 'Delete My Account' %}</h3>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">Ã</span>
</button>
</div>
<div class="modal-body">
{% trans 'Are you sure you want to delete your account?' %}
</div>
<div class="modal-footer">
<div class="left-side">
<button type="button" class="btn btn-raised btn-default"
data-dismiss="modal">{% trans 'Cancel'
%}</button>
</div>
<div class="divider"></div>
<div class="right-side">
<a href="{% url 'deleteme' request.user.id %}"
id="delete-account"
class="btn btn-raised btn-danger">{% trans 'Yes,
delete me' %}</a>
</div>
</div>
</div>
</div>
</div>
<!-- END CONFIRM MODAL -->
{% block bottomjs %}
<script>
$(function () {
$('#delete-account').on('click', function () {
$('#ms-preload, #status').show();
});
});
</script>
{% endblock %}
URLS>PY
from django.urls import path
from .views import subscriptions, subscribe, unsubscribe,deleteme,
get_discounted_value, plan_details, my_subscription, manage_account
urlpatterns = [
path('my-subscription/', my_subscription, name='my_subscription'),
path('manage-account/', manage_account, name='manage_account'),
path('subscriptions/', subscriptions, name='subscriptions'),
path('subscribe/', subscribe, name='subscribe'),
path('unsubscribe/', unsubscribe, name='unsubscribe'),
path('deleteme/<int:id>/', deleteme, name='deleteme'),
path('discounted-value/', get_discounted_value, name='discounted-value'),
path('plan-details/', plan_details, name='plan-details'),
#
re_path('discounted-value/(?P<coupon_code>([^/]+))/(?P<original_value>([0-9.]+))/',
# get_discounted_value, name='assessment_question'),
]
VIEWS
@csrf_exempt
def deleteme(request):
request.user.deleteme(request.POST)
return redirect('free_dashboard_index')
I want to pass an id through a modal, via urls.py and to hit a function in
the views to delete the user.
This is my modal:
Much appreciated for any help. Fairly new to Django. Really hope someone
can come to my rescue :-)
<!-- BEGIN CONFIRM MODAL -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">{% trans 'Delete My Account' %}</h3>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">Ã</span>
</button>
</div>
<div class="modal-body">
{% trans 'Are you sure you want to delete your account?' %}
</div>
<div class="modal-footer">
<div class="left-side">
<button type="button" class="btn btn-raised btn-default"
data-dismiss="modal">{% trans 'Cancel'
%}</button>
</div>
<div class="divider"></div>
<div class="right-side">
<a href="{% url 'deleteme' request.user.id %}"
id="delete-account"
class="btn btn-raised btn-danger">{% trans 'Yes,
delete me' %}</a>
</div>
</div>
</div>
</div>
</div>
<!-- END CONFIRM MODAL -->
{% block bottomjs %}
<script>
$(function () {
$('#delete-account').on('click', function () {
$('#ms-preload, #status').show();
});
});
</script>
{% endblock %}
URLS>PY
from django.urls import path
from .views import subscriptions, subscribe, unsubscribe,deleteme,
get_discounted_value, plan_details, my_subscription, manage_account
urlpatterns = [
path('my-subscription/', my_subscription, name='my_subscription'),
path('manage-account/', manage_account, name='manage_account'),
path('subscriptions/', subscriptions, name='subscriptions'),
path('subscribe/', subscribe, name='subscribe'),
path('unsubscribe/', unsubscribe, name='unsubscribe'),
path('deleteme/<int:id>/', deleteme, name='deleteme'),
path('discounted-value/', get_discounted_value, name='discounted-value'),
path('plan-details/', plan_details, name='plan-details'),
#
re_path('discounted-value/(?P<coupon_code>([^/]+))/(?P<original_value>([0-9.]+))/',
# get_discounted_value, name='assessment_question'),
]
VIEWS
@csrf_exempt
def deleteme(request):
request.user.deleteme(request.POST)
return redirect('free_dashboard_index')
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b3aace83-d3f1-43a7-9f10-5a1a07442608%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b3aace83-d3f1-43a7-9f10-5a1a07442608%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.