How can i get the data-vale?
<form method='get' action='#'>
<input type="submit" data-value="1" value="Edit" name="Type" />
<input type="submit" data-value="1" value="Delete" name="Type" />
if request.GET.get('Type') == 'Delete':
print (request.GET.get('Delete'))
You can work with the <button>
tag and specify a name-value pair:
<form method='get' action='#'>
<button name="Type" value="Edit" type="submit" data-value="1">Edit</button>
<button name="Type" value="Delete" type="submit" data-value="1">Delete</button>
</form>
or if you want to submit the value as well, we can do this with:
<form method='get' action='#'>
<button name="Type" value="Edit-1" type="submit">Edit</button>
<button name="Type" value="Delete-1" type="submit">Delete</button>
</form>
In that case we can check this in the view with:
if request.GET.get('Type', '').startswith('Delete'):
__, item = request.GET['Type'].split('-', 1)
In that case item
will contain the value after the hyphen.
Note :Section 9 of the HTTP protocol specifies that requests like GET and HEAD should not have side-effects, so you should not change entities with such requests. Normally POST, PUT, PATCH, and DELETE requests are used for this. In that case you make a small
<form>
that will trigger a POST request, or you use some AJAX calls.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.