Issue with CRUD Operation

31 views
Skip to first unread message

Ifeanyi Chielo

unread,
May 24, 2020, 8:38:51 PM5/24/20
to Django users
Hello,
I performed a CRUD operation and every thing is working well except two things
1. my insert form does not clear the text boxes after saving a record
2. my delete operation renders an error page after deleting a record with a message ''DoesNotExist at /delete/3/" or "AttributeError at /delete/6/" 
example of the error messages are  shown below. i also attached view.py, model.py and template file

DoesNotExist at /delete/3/

Soapprod matching query does not exist.

Request Method:

POST

Request URL:

http://localhost:8000/delete/3/

Django Version:

2.1.5

Exception Type:

DoesNotExist

Exception Value:

Soapprod matching query does not exist.

Exception Location:

C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py in get, line 399

Python Executable:

C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\python.exe

Python Version:

3.7.2

Python Path:

['C:\\Users\\IFEANYI CHIELO\\divinecrown',

 'C:\\Users\\IFEANYI '

 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37',

 'C:\\Users\\IFEANYI '

 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']

Server time:

Mon, 25 May 2020 00:03:25 +0000


or


AttributeError at /delete/6/

'str' object has no attribute 'get'

Request Method:

POST

Request URL:

http://localhost:8000/delete/6/

Django Version:

2.1.5

Exception Type:

AttributeError

Exception Value:

'str' object has no attribute 'get'

Exception Location:

C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\lib\site-packages\django\middleware\clickjacking.py in process_response, line 26

Python Executable:

C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\python.exe

Python Version:

3.7.2

Python Path:

['C:\\Users\\IFEANYI CHIELO\\divinecrown',

 'C:\\Users\\IFEANYI '

 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37',

 'C:\\Users\\IFEANYI '

 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']

Server time:

Mon, 25 May 2020 00:09:23 +0000

soapprod_form.html
views.py
models.py

Luqman Shofuleji

unread,
May 26, 2020, 3:08:53 AM5/26/20
to django...@googlegroups.com
Hi,

Please also attach the code of your list template where the delete is been executed.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b43b280d-ab19-4620-8544-133c897396f0%40googlegroups.com.

Luqman Shofuleji

unread,
May 26, 2020, 3:27:42 AM5/26/20
to django...@googlegroups.com
To clear your form after submit, just re-assign an empty form object after the form.save(). See below

def soapprod_form (requestid=0):
    if request.method == "GET":
        if id == 0:
            form = SoapprodForm()
        else:
            soapprod = Soapprod.objects.get(pk=id)
            form = SoapprodForm (instance=soapprod)
        return render(request, "soapprod_form.html", {'form': form})
    else:
        if id == 0:
            form = SoapprodForm(request.POST)
        else:
            soapprod = Soapprod.objects.get(pk=id)
            form = SoapprodForm(request.POST,instance= soapprod)
        if form.is_valid():
            form.save()
            form = SoapprodForm()
        return render(request, "soapprod_form.html", {'form': form})
Reply all
Reply to author
Forward
0 new messages