Contenido del Curso
Django: Build Your First Website
Django: Build Your First Website
Dynamic URL: Delete
Description
-
note = Note.objects.get(pk=note_id)
: This line retrieves aNote
object from the database based on its unique identifier (note_id
); -
note.delete()
: Applying thedelete()
method to theNote
object removes it from the database.
-
'note/<int:note_id>/delete/'
: This is the URL pattern. It starts with the string 'note/', followed by<int:note_id>
, which is a path converter indicating that an integer (note_id
) is expected in this part of the URL. Finally, it includes '/delete/' to signify that this path is associated with the deletion of a note; -
delete
: This is the view function that will be called when the specified URL pattern is matched. In this case, it's expected to be thedelete
function that handles the deletion of a note; -
name='delete'
: This is a name assigned to the URL pattern. It can be used in the Django templates or code to reference this specific URL pattern, making it easier to manage URLs throughout the project.
In summary, this URL pattern is designed to match URLs like 'note/1/delete/'
, where '1'
is the identifier of the note to be deleted. When a URL matching this pattern is accessed, it is expected to trigger the delete
view function.
admin.py
manage.py
my_notes
migrations
templates
base.html
note_detail.html
notes.html
admin.py
apps.py
forms.py
models.py
tests.py
urls.py
views.py
notes
asgi.py
settings.py
urls.py
wsgi.py
requirements.txt
¡Gracias por tus comentarios!