How to get attributes value of html inputs in django views

Viewed 175

I have html input like this:

<input type="text" name="download_number" class="corecharinputwidget form-control" size="10" maxlength="30" style="font-size: smaller;margin-top: 30px;" placeholder="Enter Document Number" id="id_download_number" pk="1">

and I want to recieve pk attribute value in django view.

1 Answers

You can use JQuery Ajax methods like this:

 $.ajax({
        method: "get",
        url: "your url",
        data: { 'download_number_pk': $('#id_download_number').prop('pk') }, 
        success: function (data) {
        // handle with your revived data
        }
    });

In django views just check the request like this:

if request.GET.get('download_number_pk',None):
    pk=request.GET.get('download_number_pk')
    //  You have received html input attribute
Related