Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Creation Operations | CRUD Operations
course content

Зміст курсу

Django: Build Your First Website

Creation OperationsCreation Operations

Let's rewrite our program to visually explore working with the database.

Code Explanation

AppFolder \ views.py
  • It imports the Note model from the same Django app (presumably defined in models.py);
  • The send_content function is a Django view that gets called when the URL associated with it is accessed;
  • Inside the view, a new instance of the Note model is created with the title set to "Example Title";
  • The new note is then saved to the database using new_note.save();
  • Finally, an HttpResponse is returned with the message 'Note saved'.
AppFolder \ urls.py

It imports the send_content view from the same Django app (views.py). The urlpatterns list contains a single URL pattern that maps the URL path 'send/' to the send_content view.

So, when you access the URL path 'send/', it triggers the send_content view, which creates a new Note object with the title "Example Title" and saves it to the database. The view then responds with the message 'Note saved'.

Все було зрозуміло?

Секція 4. Розділ 1
course content

Зміст курсу

Django: Build Your First Website

Creation OperationsCreation Operations

Let's rewrite our program to visually explore working with the database.

Code Explanation

AppFolder \ views.py
  • It imports the Note model from the same Django app (presumably defined in models.py);
  • The send_content function is a Django view that gets called when the URL associated with it is accessed;
  • Inside the view, a new instance of the Note model is created with the title set to "Example Title";
  • The new note is then saved to the database using new_note.save();
  • Finally, an HttpResponse is returned with the message 'Note saved'.
AppFolder \ urls.py

It imports the send_content view from the same Django app (views.py). The urlpatterns list contains a single URL pattern that maps the URL path 'send/' to the send_content view.

So, when you access the URL path 'send/', it triggers the send_content view, which creates a new Note object with the title "Example Title" and saves it to the database. The view then responds with the message 'Note saved'.

Все було зрозуміло?

Секція 4. Розділ 1
some-alt