5👍
✅
You’ve imagined an attribute called request.item
. There’s no such thing. You need to get the item from the database, via the ID passed into the function as alecxe showed.
def edit(request, item_id):
item = Item.objects.get(pk=item_id)
if request.method == 'POST':
form = EditItemForm(request.POST, instance=item)
1👍
edit()
view should allow a keyword argument item_id
:
def edit(request, item_id=None):
if request.method == 'POST':
...
- [Django]-How to get a word count on word document in python?
- [Django]-Django admin – prevent objects being saved, and don't show the user confirmation message
Source:stackexchange.com