Django, adding views to detail page

Asked 2 years ago, Updated 2 years ago, 49 views

We're learning about Jango Girls in Korean Application extension part / post Add view to detail page If you type Post.objects.get(pk=pk) in the shell, It says doesnotexist at/post/10 When I type the low-key code on the shell, ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in NameError: name 'Post' is not defined

It doesn't work at all when I open it

If the error does not appear at/post/10, then page not found 404 This solves how to add a view to the views.py file....

I can't understand what you're asking even if I read the questions I wrote again

django python

2022-09-22 21:27

1 Answers

Based on the error content, it seems that the model Post has not been imported.

If you are working on the shell, please run the code to import the Post in advance.

Typically, it should be in the same format as from appname.models importPost.

You'll get an error if you run it from the shell. Because pk is not defined. Looking at the contents of Jango Girls' page, Post.objects.get(pk=pk) should be defined in the method def post_detail(request,pk):.


2022-09-22 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.