What I’m trying to do: I have a server module called server module_1 which at this stage has only one simple deffinition
def add_name(names):
user = anvil.users.get_user()
app_tables.answers_from__user.add_row(Name=names)
answers_from__user has a column ‘name’
When I call this function using
anvil.server.call(‘add_name’,self.names)
I get this error.
AttributeError: ‘questionForm’ object has no attribute ‘names’ at [Homeform.questionForm, line 55](javascript:void(0))
I cant understand why it refers to questionForm when I’m calling a function in server module.I am calling the function from within the questionForm,but can’t figure out why it gives the error and does not accept the argument ‘names’.
What I’ve tried and what’s not working:
Code Sample:
# this is a formatted code snippet.
# paste your code between ```
I’ve bolded that part that is causing your issue. The self in self.names refers to your form, and it’s trying to access a names property on that form. The error is saying that the form doesn’t have a names property.
Without the rest of the form code it’s impossible to say what you should be doing instead.
I just looked - nowhere in your “questionForm” is there a definition of “self.names”.
At a guess, are you trying to pass the names in your text area control called “text_area_1”?
If so, you need to pass “self.text_area_1.text”.
Python will look for a class property called “names”, either in the form of a control or a property you yourself have defined. As it is not finding one, you are seeing that error.
Thanks for looking into this for me,I appreciate your help.
I am trying to have the definition in the server module, add names to answers_from__users table,and am trying to call the function which is in the server module (that I think should do the saving) from line 55 in questionForm.
Does this make sense?
As @david.wylie and @jshaffstall have pointed out, you are passing an argument to your add_name function that hasn’t been defined. What are you trying to pass into your function? In other words, what are you expecting self.names to be?
Also, in that cloned app, you’ve defined a server function called add_name, but on the client, you are trying to call a function called add_names.
Sorry for all the confusion,I am new to all of this and trying my best to be clear but a large part of the problem is my lack of competence in both anvil and python
Anyhow…
I have changed the code slightly so the add_name function is called when text is entered in text_area_1
I have a data table called answers_from__user and in that table I have a column called name,
I am trying to get the input in text area_1 to be saved to name in answers_from__user