Home:ALL Converter>Django: custom button in admin change form return bad url for custom view function

Django: custom button in admin change form return bad url for custom view function

Ask Time:2021-10-01T22:42:22         Author:Stefan Nitica

Json Formatter

I have problems to link my custom button from change_form.html to my view function.

pic : admin change form custom button

change_form.html

{% extends "admin/change_form.html" %}
{% load i18n %}
{% block title %} Send Email  {% endblock %}
{% block content %}

{% if request.resolver_match.url_name == 'requests_requests_change'  %}
    <div class="submit-row">
                {% csrf_token %}
            <a href="{% url 'requests:send-email' original.pk %}"
                 class="button" style="background-color: #F08000;float: left">Request Subscription
            </a>
    </div>
            {% endif %}
        {{ block.super }}
{% endblock %}

views.py

from django.shortcuts import render, redirect

def send_email(request, requests_id):
    return redirect('')  # or whatever to test the url

urls.py

from django.urls import path

from . import views

app_name = 'requests'
urlpatterns = [
    path('<int:pk>/send-email/', views.send_email, name='send-email'),
]

main project urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
                  path('', admin.site.urls),  # admin site administration
                  path('requests/', include('requests.urls')),
              ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

pic: error message

Any help would be great! Thanks!

Author:Stefan Nitica,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69407790/django-custom-button-in-admin-change-form-return-bad-url-for-custom-view-functi
yy