3

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?

user695652
  • 4,105
  • 7
  • 40
  • 58
  • Have you tried to specify `method='GET'` for your sayhello function in the decorator? Just to check. – maulik13 Jul 02 '13 at 08:18
  • hm, I think you have a point here. If I register it with method='GET' I get the error message: dajaxice_register() got an unexpected keyword argument 'method'. Do you know why this is? It looks like the installation might be flawed? – user695652 Jul 02 '13 at 12:26
  • That is strange. Do you know where this exception occurs in the call stack? And what version of dajaxice are you using? On the latest GitHub code I don't see such exception, unless I missed something. – maulik13 Jul 02 '13 at 12:58
  • maybe it works only with strings, try: `{'dir': '3'}` – Alp Jul 04 '13 at 11:09
  • You could use JSON.stringify(data) as well. – maulik13 Jul 04 '13 at 11:47

2 Answers2

1

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
Patrick Z
  • 2,119
  • 1
  • 16
  • 10
0

change the sayhello to :

def sayhello(request):
  my_dict=json.loads(request.POST['argv'])
  dir=my_dict['dir']
  print(dir)