NameError: name 'anvil' is not defined (client-side)

Hi,
I am very new to using Anvil. I am basically trying to load an Excel workbook on the client side and pass it onto a Jupyter notebook on the server side (currently my own machine). I have the following code running on the client side:

from ._anvil_designer import Form1Template
from anvil import *
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
from anvil.tables import app_tables

class Form1(Form1Template):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

    # Any code you write here will run before the form opens.

  def file_loader_1_change(self, file, **event_args):
    """This method is called when a new file is loaded into this FileLoader"""
    tod_data = anvil.server.call('tod_preprocess', file)

self.tod_table.content = anvil.server.call('df_final') # displaying the final dataframe

However, I am getting the following error:

NameError: name 'anvil' is not defined

  • at Form1, line 19

I know this topic is tagged as fixed, but I wanted to know if I am doing anything wrong.

Which line is line 19?

Never mind I see it. It is because your last line is outside the class definition. You need to check the indenting on line 19

1 Like

You need to import anvil.server since you’re using that in your last line.

3 Likes

Oh snap I didn’t even see that… Eyes like a hawk Mr Campbell

And fast at responding too

3 Likes

Thank you both, I appreciate the help.