[Fixed]-Determine Django User-id from Javascript

1👍

Basically what you are looking to do is get the user’s info in your view and return it in the view’s context. Once that is done, you can assign it to a javascript variable like any other Django variable using the {{ my_var }} notation.

Your view.py

def mysampleview(request):
    ...
    current_user_id = request.user.id
    context['current_user_id'] = current_user_id
    ...
    # Then return your context

yourjs.js

var user_id = {{ current_user_id }};
....
👤Ryan

Leave a comment