<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def lostitem_modify_view(request, item_id=None):
 """Modify a lostitem. id: lostitem id """

    if request.method == "POST":
        lostitem = get_object_or_404(LostItem, id=item_id)
        form = LostItemForm(request.POST, instance=lostitem)
        if form.is_valid():
            obj = form.save()
            logger.debug(form.cleaned_data)
            # SAFE HTML
            obj.description = safe_html(obj.description)
            obj.save()
            messages.success(request, "Successfully modified lost item.")
            return redirect("lostitem_view", obj.id)
        else:
            messages.error(request, "Error adding lost item.")
    else:
        lostitem = get_object_or_404(LostItem, id=item_id)
        form = LostItemForm(instance=lostitem)

    context = {"form": form, "action": "modify", "id": item_id, "lostitem": lostitem}
    return render(request, "lostfound/lostitem_form.html", context)