Course Content
Django: First Dive
Django: First Dive
2. Write the First Page
4. Working with Database
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 Task
button to solve this task.
Task
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:
Write the View functionality for the POST method with data extracting:
- Save the
request.POST
dictionary into thedata
variable. - Create the
Post
class instance namednew_post
- Assign attributes
title
andtext
fromdata
dictionary to thenew_post
instance. - Save changes in the database.
- Return the
HttpResponse
object passing"<h1>Complete!</h1>"
!
Task
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:
Write the View functionality for the POST method with data extracting:
- Save the
request.POST
dictionary into thedata
variable. - Create the
Post
class instance namednew_post
- Assign attributes
title
andtext
fromdata
dictionary to thenew_post
instance. - Save changes in the database.
- Return the
HttpResponse
object passing"<h1>Complete!</h1>"
!
Everything was clear?
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 Task
button to solve this task.
Task
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:
Write the View functionality for the POST method with data extracting:
- Save the
request.POST
dictionary into thedata
variable. - Create the
Post
class instance namednew_post
- Assign attributes
title
andtext
fromdata
dictionary to thenew_post
instance. - Save changes in the database.
- Return the
HttpResponse
object passing"<h1>Complete!</h1>"
!
Task
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:
Write the View functionality for the POST method with data extracting:
- Save the
request.POST
dictionary into thedata
variable. - Create the
Post
class instance namednew_post
- Assign attributes
title
andtext
fromdata
dictionary to thenew_post
instance. - Save changes in the database.
- Return the
HttpResponse
object passing"<h1>Complete!</h1>"
!
Everything was clear?
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 Task
button to solve this task.
Task
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:
Write the View functionality for the POST method with data extracting:
- Save the
request.POST
dictionary into thedata
variable. - Create the
Post
class instance namednew_post
- Assign attributes
title
andtext
fromdata
dictionary to thenew_post
instance. - Save changes in the database.
- Return the
HttpResponse
object passing"<h1>Complete!</h1>"
!
Task
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:
Write the View functionality for the POST method with data extracting:
- Save the
request.POST
dictionary into thedata
variable. - Create the
Post
class instance namednew_post
- Assign attributes
title
andtext
fromdata
dictionary to thenew_post
instance. - Save changes in the database.
- Return the
HttpResponse
object passing"<h1>Complete!</h1>"
!
Everything was clear?
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 Task
button to solve this task.
Task
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:
Write the View functionality for the POST method with data extracting:
- Save the
request.POST
dictionary into thedata
variable. - Create the
Post
class instance namednew_post
- Assign attributes
title
andtext
fromdata
dictionary to thenew_post
instance. - Save changes in the database.
- Return the
HttpResponse
object passing"<h1>Complete!</h1>"
!