Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Dynamic URL | Forms and Dynamic URLs
Django: Build Your First Website

Dynamic URLDynamic URL

Description

AppFolder \ veiws.py

.get(pk=note_id): This get method is used to retrieve a single object from the database that matches certain criteria. In this case, the criteria is the identifier of the record (pk=note_id), which is passed as the note_id parameter.

note = ...: The result of the call to Note.objects.get(pk=note_id) is assigned to the variable note. Therefore, the variable note now contains an object of type Note from the database that corresponds to the identifier passed in note_id.

AppFolder \ urls.py

path('note/<int:note_id>/', ...): This part defines a URL pattern using the path function. It indicates that the URL should start with 'note/' followed by an integer (<int:note_id>). The angle brackets < > are used to capture the value and pass it as a parameter to the associated view function (note_detail).

note_detail.html
html

index.html

css

index.css

js

index.js

value="{{ note.title }}": The value attribute is set using jinja syntax within double curly braces. This means that the value of the title attribute of the note object will be inserted into this input field.

<textarea>: This is an HTML tag that defines a multiline text input control, often used for larger amounts of text, such as comments or descriptions.

{{ note.content }}: The content of the textarea is set using jinja syntax within double curly braces. This means that the value of the content attribute of the note object will be inserted into the textarea.

Everything was clear?

Section 6. Chapter 4
course content

Course Content

Django: Build Your First Website

Dynamic URLDynamic URL

Description

AppFolder \ veiws.py

.get(pk=note_id): This get method is used to retrieve a single object from the database that matches certain criteria. In this case, the criteria is the identifier of the record (pk=note_id), which is passed as the note_id parameter.

note = ...: The result of the call to Note.objects.get(pk=note_id) is assigned to the variable note. Therefore, the variable note now contains an object of type Note from the database that corresponds to the identifier passed in note_id.

AppFolder \ urls.py

path('note/<int:note_id>/', ...): This part defines a URL pattern using the path function. It indicates that the URL should start with 'note/' followed by an integer (<int:note_id>). The angle brackets < > are used to capture the value and pass it as a parameter to the associated view function (note_detail).

note_detail.html
html

index.html

css

index.css

js

index.js

value="{{ note.title }}": The value attribute is set using jinja syntax within double curly braces. This means that the value of the title attribute of the note object will be inserted into this input field.

<textarea>: This is an HTML tag that defines a multiline text input control, often used for larger amounts of text, such as comments or descriptions.

{{ note.content }}: The content of the textarea is set using jinja syntax within double curly braces. This means that the value of the content attribute of the note object will be inserted into the textarea.

Everything was clear?

Section 6. Chapter 4
some-alt