Fast HTML - ** Server Error NotFoundError: Need k**
Sep 06, 2024 am 06:05 AMFast 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 <class 'sqlite_minutils.db.Table'>. 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 <class 'sqlite_minutils.db.Table'> is a subclass of the type <class 'sqlite_utils.db.Table'>. 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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to Use Python to Find the Zipf Distribution of a Text File

How Do I Use Beautiful Soup to Parse HTML?

How to Perform Deep Learning with TensorFlow or PyTorch?

Introduction to Parallel and Concurrent Programming in Python

Serialization and Deserialization of Python Objects: Part 1

Mathematical Modules in Python: Statistics

How to Implement Your Own Data Structure in Python
