Create Post with Input Data
Note
The presented code for the task is part of the framework and cannot work separately, so errors will be received when you try to
Run Code. Use theSubmit Taskbutton to solve this task.
Swipe to start coding
Now, let's improve our view to save new posts in the database!
The received context via HTTP request is the request.POST dictionary. The keys of the dictionary is:
"csrfmiddlewaretoken"
"title"
"text"
Write the View functionality for the POST method with data extracting:
-
Save the
request.POSTdictionary into thedatavariable. -
Create the
Postclass instance namednew_post -
Assign attributes
titleandtextfromdatadictionary to thenew_postinstance. -
Save changes in the database.
-
Return the
HttpResponseobject passing
"<h1>Complete!</h1>"!
Solution
Merci pour vos commentaires !
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Résumer ce chapitre
Expliquer le code dans file
Expliquer pourquoi file ne résout pas la tâche
Awesome!
Completion rate improved to 3.45
Create Post with Input Data
Glissez pour afficher le menu
Note
The presented code for the task is part of the framework and cannot work separately, so errors will be received when you try to
Run Code. Use theSubmit Taskbutton to solve this task.
Swipe to start coding
Now, let's improve our view to save new posts in the database!
The received context via HTTP request is the request.POST dictionary. The keys of the dictionary is:
"csrfmiddlewaretoken"
"title"
"text"
Write the View functionality for the POST method with data extracting:
-
Save the
request.POSTdictionary into thedatavariable. -
Create the
Postclass instance namednew_post -
Assign attributes
titleandtextfromdatadictionary to thenew_postinstance. -
Save changes in the database.
-
Return the
HttpResponseobject passing
"<h1>Complete!</h1>"!
Solution
Merci pour vos commentaires !
single