2
The ‘error’ event in your JS will not hit, because your view doesn’t return an error.
I’m not 100% sure what you want, but you can return a 404.
views.py
def GetProduct(request, upc):
try:
item = Item.objects.get(upc=upc)
except Item.DoesNotExist:
return HttpResponseNotFound()
return render(request, "alpha/get-product.html", {'item': item})
template
error: function() {
$('#extra').html('Please enter valid UPC code.');
$("input").removeAttr('disabled');
}
0
Thanks for the time you guys have put to this question. I have solved it. I built a logic in the template file like the following:
{% if item %}
[ show form with some disabled fields ]
{% else %}
[ show the same form with all fields enabled ]
{% endif %}
Thanks.
- [Answered ]-Pillow upload path in pythonanewhere?
- [Answered ]-Getting DUPLICATE error when logging in existing user with Django
- [Answered ]-How do I save to Django's database manually?
- [Answered ]-Django select how to remember chosen value?
- [Answered ]-Cant figure out right queryset for json in django
Source:stackexchange.com