[Django]-Django: ValueError at /save_page/ – invalid literal for int() with base 10: 'My World'

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 the title field definition (underlying table needs to be recreated then, no code modification needed)
  • add a unique=True to the title field definition and query with get(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

Leave a comment