Реверс для с аргументами '(' ',' ',' ',' ')' не найден. Ошибка 1 шаблона - PullRequest
1 голос
/ 27 января 2020
I am adding a URL in my page to download CSV. Below is the URL. I am getting below error.

    Reverse for 'kitty_download' with arguments '('', '', '', '')' not found. 1 pattern(s) tried: ['kitty_download/(?P<codep>[-a-zA-Z0-9_]+)/(?P<slotp>[-a-zA-Z0-9_]+)/(?P<customerp>[-a-zA-Z0-9_]+)$']

     <td><a style="margin-top:5px;margin-left:20px"  href="{% url 'kitty_download' codep slotp customerp %} ?{{ code1 }} ?{{ slot1 }}?{{ customer1 }}">CSV Download</a> </td>

Path is Below.
-----------------

    path('kitty_download/<slug:codep>/<slug:slotp>/<slug:customerp>', views.kitty_download, name='kitty_download')    

Просмотр - это функция просмотра, которую я использую для загрузки CSV

    def kitty_download(request,codep,slotp,customerp): 
        url_name = request.resolver_match.url_name
        print(url_name)
        print(codep) 
        print(slotp) 
        print(customerp) 
        kitty_members = kitty_member.objects.all().order_by('cretime')

        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] ='attachment; filename="kitty_member.csv"'    
        writer = csv.writer(response, delimiter = ',')    
        writer.writerow(['kitty Member Details']) 
        writer.writerow([]) 
        writer.writerow(['Code','Slot','Customer','Status'])
        for i in kitty_members:
            writer.writerow([i.code,i.slot,i.customer,i.status])
        return response

~ I am renderng kitty_member.html from kitty_member_view view. this is the  parent page from where i am using the link of downloading the CSV   
 def kitty_member_view(request):    
     kitty_member_list = kitty_member.objects.all().order_by('cretime')
        code1 = str(request.GET.get('code'))
        slot1 = request.GET.get('slot')
        customer1 = request.GET.get('customer')
        status1 = str(request.GET.get('stat'))
        if (code1 is not None and code1 != 'None' and code1 != ''):
            kitty_member_list = kitty_member_list.filter(code=code1)
        if (slot1 is not None and slot1 != 'None'and slot1 != ''):
            kitty_member_list = kitty_member_list.filter(slot=slot1)
        if (customer1 is not None and customer1 != 'None'and customer1 != ''):
            kitty_member_list = kitty_member_list.filter(customer=customer1)
        if (status1 is not None and status1 != 'None' and status1 != ''):
            kitty_member_list = kitty_member_list.filter(status=status1)

        paginator = Paginator(kitty_member_list, 9)
        page = request.GET.get('page')
        kitty_member_list = paginator.get_page(page)

        kittys = kitty.objects.all()
        customers = customer.objects.all().distinct('mobile')

        ctx = {'kitty_member': kitty_member_list,'customer': customers, 'kitty': kittys, 'code1':code1,'slot1':slot1,'customer1':customer1,'status1':status1}

        return render(request, 'kitty_member/kitty_member_view.html', ctx)

// kitty_member_view. html, откуда я использую URL загрузки. Я передаю // 4 параметра, которые дают эту ошибку. Я могу напечатать значения, которые я // передаю через URL.

{% extends 'base.html' %}
{% load static %}

{% block content %}
<form class="form-signin" action="{% url 'kitty_member_view' %}" method="get">
    {% csrf_token %}
    <!-- <div class="container"> -->
        <div class="form-row">
            <div class="mb-3 ml-4">
                <select class="custom-select-sm" name="code" id="code" placeholder="Kitty Code"
                    value="{{ code1 }}" onchange="callview()">
                    {% if code1 == 'None'  %}
                    <option value="{{ code1 }}"> Select Kitty Code </option>
                    {% else %}
                    <option value="{{ code1 }}"> {{ code1 }}  </option>
                    {% endif %}
                    {% for i in kitty %}
                    <option value="{{ i.code }}"> {{ i.code|add:' - '|add:i.name }} </option>
                    {% endfor %}
                </select>                
            </div>
            <!-- <div class="mb-3 ml-2">
                <input type="text" name="slot" list="slot" placeholder="Slot" />
                <datalist id="slot">
                </datalist>
            </div> -->

            <div class="mb-3 ml-2">
                <select class="custom-select-sm" name="slot" id="slot" placeholder="Slot"  value="">
                {% if slot1 is None   %}
                <option value="{{ slot1 }}">Select Slot </option>
                {% else %}
                <option value="{{slot1}}"> {{slot1}} </option>
                {% endif %}
                </select>
            </div>

            <div class="mb-3 ml-2">
                <select class="custom-select-sm" name="customer" id="customer" placeholder="Customer">
                    {% if  customer1  == 'None' or customer1  is None %}
                         <option value="{{ customer1 }}">Choose Customer...</option>
                    {%else%}
                         <option value="{{ customer1 }}">{{ customer1 }}</option>
                    {%endif%}
                    {% for i in customer %}
                    <option value="{{ i.mobile }}"> {{ i.mobile|add:' - '|add:i.name }} </option>
                    {% endfor %}
                </select>
            </div>

            <div class="mb-3 ml-2">
                <select class="custom-select-sm" name="stat" id="stat" placeholder="Status">
                        {% if  status1  == 'None' %}
                        <option value="{{ status1 }}">Choose Status...</option>
                        {%else%}
                        <option value="{{ status1 }}">{{ status1 }}</option>
                        {%endif%}
                        <option>A</option>
                        <option>I</option>
                    </select>
           </div>

            <div class="mb-3 ml-2">
                <button type="submit" class=" btn btn-primary btn-sm" role="button">Search</button>
            </div>
            <div class="mb-3 ml-2">
                <a href="{% url 'kitty_member_view'%}" class="btn btn-primary btn-sm" role="button">Reset</a>               
            </div>
            <div class="mb-3 ml-2">
                    <td><a style="margin-left:50px" href="{% url 'kitty_member' %}" class="btn btn-primary btn-sm" role="button">Add Member</a></td>

// Отсюда я использую ссылку для скачивания CSV Скачать {{status1}} {{customer1}} {{slot1}} {{code1}} ->

<div class="pagination">
    {% if  kitty_member.has_previous %}
    <a href="?page=1">First &nbsp; </a>
    <a href="?page={{kitty_member.previous_page_number}}">&nbsp; Pre &nbsp;</a>
    {% endif %}
    {% for p in kitty_member.paginator.page_range %}
    {% if  kitty_member.number == p %}
    <strong class="whitec" style="font-size: 1.3pc">{{p}} &nbsp; </strong>
    {% else %}
    <a class="redc" href="?page={{p}}">&nbsp; {{p}} &nbsp;</a>
    <!-- {{p}}  &nbsp; -->
    {% endif %}
    {% endfor %}

    {% if  kitty_member.has_next %}
    <a href="?page={{kitty_member.next_page_number}}">&nbsp; Next &nbsp;</a>
    <a href="?page={{kitty_member.paginator.num_pages}}">&nbsp;Last </a>
    {% endif %}
</div>

<table class="table table-dark">
    <thead>
        <tr>
            <th scope="col">#</th>
            <th scope="col">Kitty Code</th>
            <th scope="col">Kitty Name</th>
            <th scope="col">Slot</th>
            <th scope="col">Customer</th>
            <th scope="col">Customer Name</th>
            <th scope="col">Status</th>
            <th scope="col">Details</th>
            <th scope="col">Edit</th>
            <th scope="col">Delete</th>
        </tr>
    </thead>

    {% if kitty_member %}
    {% for i in kitty_member %}

    <tbody>
        <tr>
            <td>{{ forloop.counter0|add:kitty_member.start_index}} </td>
            <td>{{ i.code }} </td>
            {% for j in kitty %}
            {% if i.code == j.code %}
            <td>{{ j.name }} </td>
            {% endif %}
            {% endfor %}
            <td>{{ i.slot }} </td>
            <td>{{ i.customer }} </td>

            <td>
                {% for j in customer %}
                {% if i.customer == j.mobile %}
                {{ j.name }}
                {% endif %}
                {% endfor %}
            </td>
            <td>{% if i.status == 'A' %}
                {{ 'Active' }}
                {% else %}
                {{ 'Inactive' }}
                {% endif %}
            </td>
            <td><a href="{% url 'kitty_member_details' i.id %}" class="btn btn-primary btn-sm" role="button">Details</a>
            </td>
            <td><a href="{% url 'kitty_member_edit' i.id %}" class="btn btn-primary btn-sm" role="button">Edit</a></td>
            {% if i.status == 'A' %}
            <td><a href="{% url 'kitty_member_delete' i.id %}" class="btn btn-warning btn-sm confirm-delete"
                    role="button" onclick="return confirm('Do you want to delete this Slot?')">Delete</a> </td>
            {% else %}
            <td><a href="{% url 'kitty_member_activate' i.id %}" class="btn btn-warning btn-sm confirm-delete"
                    role="button" onclick="return confirm('Do you want to Activate this Slot?')">Activate</a> </td>
            {% endif %}
        </tr>
    </tbody>

    {% endfor %}
    {% endif %}
</table>
{% endblock %}
...