Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError : got multiple values for argument 'reports_pk'

I am currently running into the above error when trying to print some client details to a CSV file.

I do understand what the error is stating, however, I don’t see where the error occurs in my code.

Please see the below code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Views.py function:

def printViewCustomers(reports_pk):
    pkForm = get_object_or_404(SettingsClass, pk=reports_pk)

    complexName = pkForm.Complex

    connect = pyodbc.connect('DRIVER={SQL Server};'
                             'DATABASE=' + complexName + ';'
                             )

    viewCustomersSQL = ' Select Account , Name , Contact_Person , Telephone , Telephone2 , Fax1 , Fax2, EMail from dbo.Client Where DCLink <> 1 '

    cursor = connect.cursor();
    cursor.execute(viewCustomersSQL);
    viewCustomersData = cursor.fetchall()
    cursor.close()
    viewCustomers = []
    for row in viewCustomersData:
        rdict = {}
        rdict["Account"] = row[0]
        rdict["Name"] = row[1]
        rdict["Contact_Person"] = row[2]
        rdict["Telephone"] = row[3]
        rdict["Telephone2"] = row[4]
        rdict["Fax1"] = row[5]
        rdict["Fax2"] = row[6]
        rdict["Email"] = row[7]
        viewCustomers.append(rdict)

    # Starting CSV
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename=" ' + complexName + ' Customer Details.csv"'
    writer = csv.writer(response)

    writer.writerow([
        'Unit',
        'Name',
        'Contact Person',
        'Telephone 1',
        'Telephone 2',
        'E-mail'
    ])

    for x in viewCustomers:
        writer.writerow([
            x["Account"],
            x["Name"],
            x["Contact_Person"],
            x["Telephone"],
            x["Telephone2"],
            x["Email"]
        ])

HTML refference to the function:

{% extends "main/base.html"%}

{% block content%}
<h1 style=" text-align: center">Reports</h1>
<hr>
 <br>

{% for x in model %}
    <div class="row mb-3">
        <div class="col">
            <a href="{% url 'DisplayCustomers' reports_pk=x.pk %}" class="list-group-item list-group-item-action list-group-item-primary">{{ x.Complex }} Details (Web View)</a>
        </div>
        <div class="col">
            <a href="{% url 'printViewCustomers' reports_pk=x.pk %}" class="list-group-item list-group-item-action list-group-item-success">Print {{ x.Complex }} Details to csv</a>
        </div>
    </div>
    <br>
{% endfor %}

{% endblock %}

URLS line

   path('accConnect/printViewCustomers/<int:reports_pk>', views.printViewCustomers , name='printViewCustomers'),

Complete Error Message:

TypeError at /accConnect/printViewCustomers/27
printViewCustomers() got multiple values for argument 'reports_pk'
Request Method: GET
Request URL:    http://127.0.0.1:8000/accConnect/printViewCustomers/27
Django Version: 3.2
Exception Type: TypeError
Exception Value:    
printViewCustomers() got multiple values for argument 'reports_pk'
Exception Location: C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py, line 181, in _get_response
Python Executable:  C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\python.exe
Python Version: 3.9.4
Python Path:    
['C:\\Users\\KylePOG\\Documents\\GMA Programming\\accConnect',
 'C:\\Users\\KylePOG\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip',
 'C:\\Users\\KylePOG\\AppData\\Local\\Programs\\Python\\Python39\\DLLs',
 'C:\\Users\\KylePOG\\AppData\\Local\\Programs\\Python\\Python39\\lib',
 'C:\\Users\\KylePOG\\AppData\\Local\\Programs\\Python\\Python39',
 'C:\\Users\\KylePOG\\AppData\\Roaming\\Python\\Python39\\site-packages',
 'C:\\Users\\KylePOG\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32',
 'C:\\Users\\KylePOG\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32\\lib',
 'C:\\Users\\KylePOG\\AppData\\Roaming\\Python\\Python39\\site-packages\\Pythonwin',
 'C:\\Users\\KylePOG\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages']
Server time:    Thu, 13 Jan 2022 13:27:41 +0000
Traceback Switch to copy-and-paste view
C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py, line 47, in inner
                response = get_response(request) …
▶ Local vars
C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py, line 181, in _get_response
                response = wrapped_callback(request, *callback_args, **callback_kwargs) …
▶ Local vars

As per the above code, everything seems to be in order compared to other functions where I have printed CSV’s

>Solution :

The first argument to your function printViewCustomers must be request. Just update your views.py to

def printViewCustomers(request, reports_pk):
    pkForm = get_object_or_404(SettingsClass, pk=reports_pk)

    complexName = pkForm.Complex

    ...........
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading