Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dajaxice: passing an argument to a python function

Using Dajaxice I want to pass a parameter to a python function.

In the html file I have the following statement

<a href="#" onclick="Dajaxice.myapp.sayhello(Dajax.process,{'dir':3} )"> <i class="icon"></i></a>

and in my ajax.ps file I have the function

@dajaxice_register
def sayhello(request, dir):
    print(dir)

It works fine if I remove the second argument dir in both the html and the python file, but with having dir, I get the error message "Something goes wrong".

Does anybody know what could be the issue here?

like image 296
user695652 Avatar asked Jan 23 '26 02:01

user695652


1 Answers

if you use Python 3.*, then in module dajaxIce make the changes file venv/lib/python3.2/site-packages/dajaxice/views.py

    def safe_dict(d):
        """
        Recursively clone json structure with UTF-8 dictionary keys
        http://www.gossamer-threads.com/lists/python/bugs/684379
        """
        if isinstance(d, dict):
            return dict([(k, safe_dict(v)) for k, v in d.items()])
        elif isinstance(d, list):
            return [safe_dict(x) for x in d]
        else:
            return d
like image 132
Patrick Z Avatar answered Jan 25 '26 18:01

Patrick Z