3👍
✅
As you didn’t specify a PK in your model, your Article’s PK is the Django default; an autoincremented integer (which you can refer to by either ‘id’ or ‘pk’). Hence, when you query
article = Article.objects.get(pk=request.POST["title"])
you got the above error, as Django expects an integer for the PK. You either want to:
- add
primary_key=True
to thetitle
field definition (underlying table needs to be recreated then, no code modification needed) - add a
unique=True
to thetitle
field definition and query withget(title=request.POST["title"])
, unique constraint must be created on db level
You can of course query by title, without the additional unique constraint, but it may lead to errors in future if the same title is present on two models and you lookup via .get().
👤alko
0👍
You need to check URL in your template.
you need to pass the integer id to url {{user.id}} because url need to have integer value in template.
Ex. url:- /polls/{{user.id}}/
Hope this will work for others.
👤Wagh
Source:stackexchange.com