I am a Newbie, was trying to follow a tutorial and it seems examples provided don’t work well. My issue lies with an associative table which list skills for a given user profile. One user can have many skills. my add/edit functionality works well, the problem lies in the delete of a skill. the profile model has a field called skills with a manytomanyfield property
URL Path: path(‘delete-skill/str:pk/’, views.deleteSkill, name=‘delete-skill’)
View Function:
@login_required(login_url=‘login’)
def deleteSkill(request, pk):
print('Skill Primary Key == ', pk)
profile = request.user.profile
skill = profile.skills.get(id=pk)
print(‘Skill Query Value’, skill.id)
if request.method == 'POST':
skill.delete()
messages.success(request, 'Skill has been removed from your profile!')
return redirect('account')
context = {'object': skill}
return render(request, 'delete-object.html', context)
This is the error:
Page not found (404)
The current path,delete-skill/7055d0f6-1736-44cb-86bf-92eb98c8159b/'
, didn’t match any of these.
If I look in the users_skill and the users_profile_skill(associative table) I find the skill_id in question.
The input is type=‘submit’ and method=‘POST’
The confirm Delete page displays the view path correctly and the pk being passed.
http://localhost:8000/delete-skill/7055d0f6-1736-44cb-86bf-92eb98c8159b/
In the Django Console I see several GET requests, but don’t understand where they are originating from
Skill Primary Key == 7055d0f6-1736-44cb-86bf-92eb98c8159b
Skill Query Value 7055d0f6-1736-44cb-86bf-92eb98c8159b
[13/May/2022 16:04:50] “GET /delete-skill/7055d0f6-1736-44cb-86bf-92eb98c8159b/ HTTP/1.1” 200 2466
[13/May/2022 16:04:50] “GET /static/js/main.js HTTP/1.1” 404 1890
Not Found: /delete-skill/7055d0f6-1736-44cb-86bf-92eb98c8159b/’
[13/May/2022 16:06:05] “POST /delete-skill/7055d0f6-1736-44cb-86bf-92eb98c8159b/’ HTTP/1.1” 404 4401
I have read thru many blogs, the Django documentation on many to many object reference, but I am not finding a clear example of a delete of an individual record from an associative table.
Thanks for looking.