Home  >  Article  >  Backend Development  >  Fast HTML - ** Server Error NotFoundError: Need k**

Fast HTML - ** Server Error NotFoundError: Need k**

WBOY
WBOYOriginal
2024-09-06 06:05:38988browse

Fast HTML - ** Server Error NotFoundError: Need k**

Fast HTML - 500 Server Error NotFoundError: Need 2 pk

In case anybody runs into this issue using fast HTML where they are trying to get rows from a table with multiple primary keys And get some variation of need 2 PK or need two primary keys

Question

500 Server Error NotFoundError: Need 2 pk

My schema are defined as:

users.create(dict(username=str, pwd=str, role=str), pk='username',transform=True)
imgs.create(id=int, username=str, mime=str, b64=str, created_at=str, score=int, pk=('id', 'username'),transform=True)
...
imgs = imgs() # This Is where I'm trying to return the list of images.

Answer

To be explicit: the problem is that the table is expecting two primary keys.

And you can do so like this: imgs[['1', "admin"] as per the mini data API Spec. But, this returns one image.

Say you wanna get all of the images by a specific user:

users.username = "admin"
imgs = imgs.rows_where("username = ?", [users.username]), None))

"Give me all the rows where the username is 'admin' (And if not found give me None)"

Or how about getting the first image that matches a specific ID:

id = 0
img = next(imgs.rows_where("id = ?", [id]), None)

"Give me the first row where the id is 0, (And if not found give me None)"


Where imgs is of type . And next returns the first item; the second argument is the default.

Summary and other details

There may be a more idiomatic fast HTML way to do this. However I do like how the expressions read nicely.

And

It's worth noting that the type of is a subclass of the type . So we can check out the docs for that here https://sqlite-utils.datasette.io/en/stable/python-api.html#listing-rows

The above is the detailed content of Fast HTML - ** Server Error NotFoundError: Need k**. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn