Hello everyone! My name is Andrea, I am very impressed with many aspects of Anvil, and I am trying to see if I can build a project on this platform.
I am currently going through the docs and tutorials.
I am facing some issues in step 4 (Chapter 5) of the tutorial
/learn/tutorials/database-backed-apps/chapter-5
My app
I have gone through the code of the cloned app line by line.
The error is
TypeError: ‘NoneType’ does not support indexing. Did you initialise all data binding sources before initialising this component?
Error binding [text of category_label] to self.item[‘category’][‘name’]:'NoneType' does not support indexing
at [ArticleView, line 12]called from [Homepage, line 20] called from [Homepage, line 16]
I have read previous posts on this tutorial on the forum, but could not find a solution. Could someone please look into this?
Hi Andrea, and welcome! Please provide a clone link to your app (assuming it doesn’t contain anything confidential), as opposed to a link to the running app. See the instructions here: Anvil Docs | Cloning Apps
The error TypeError: ‘NoneType’ does not support indexing was caused by the Data Binding of the category_label in your ArticleView Form trying to use square brackets on something that’s None.
The Data Binding was self.item['category']['name']. In this instance self.item is an article from your database and one of the articles didn’t have a category linked, so the value of self.item['category'] is None. Therefore, trying to use square brackets on it will produce the error you’re seeing.
For more information, my colleague Meredydd explained this in more depth here:
If you add a category to the article row that is missing it, your error will be solved.