[Answer]-Django – allow user to set something in database

1👍

In a Django template, you cannot call a Python function with parameters. See https://docs.djangoproject.com/en/1.4/topics/templates/#variables . That’s why you get no error message when you write {{request.user.get_profile.get_language}} (actually, your function is called without parameters, and the resulting exception is swallowed by Django).

Also, you cannot use the lang parameter, which is a client-side JavaScript function parameter, in a Python function on the server side. Try calling the function using AJAX – you’ll need to add another view function for this, and I strongly suggest you don’t use bare JavaScript, but a library like jQuery.

For your actual problem (letting the user set his preferred language), there’s already a function for that in Django’s internationalization package.

👤Simon

Leave a comment