Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Create Post with Input Data | Request Handling
Django: First Dive

bookCreate 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 the Submit Task button to solve this task.

Opgave

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:

  1. Save the request.POST dictionary into the data variable.

  2. Create the Post class instance named new_post

  3. Assign attributes title and text from data dictionary to the new_post instance.

  4. Save changes in the database.

  5. Return the HttpResponse object passing
    "<h1>Complete!</h1>"!

Løsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 6. Kapitel 4
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Opsummér dette kapitel

Explain code

Explain why doesn't solve task

close

Awesome!

Completion rate improved to 3.45

bookCreate Post with Input Data

Stryg for at vise menuen

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 the Submit Task button to solve this task.

Opgave

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:

  1. Save the request.POST dictionary into the data variable.

  2. Create the Post class instance named new_post

  3. Assign attributes title and text from data dictionary to the new_post instance.

  4. Save changes in the database.

  5. Return the HttpResponse object passing
    "<h1>Complete!</h1>"!

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

close

Awesome!

Completion rate improved to 3.45
Sektion 6. Kapitel 4
single

single

some-alt