I'm Trying to pass data from javascript on a page to another view in my django project.But it seems the view isn't getting called. What I want to do is that Using JS I want to just get data from page containing the JS and print it from django view to console.
js on html page:
<script>
var URL="{% url 'projects:Unread' %}"
function Unread(){
var data = {'count': '5', 'X-csrfmiddlewaretoken': csrfmiddlewaretoken};
$.post(URL, data);
}
</script>
somewhere from page I'm calling this function,I have used an alert to make sure it is called.
my urls.py :
path('notification/',Unread,name='Unread')
my view:
def Unread(request):
count=request.body['count']
print("hello")
print("count status ",count)
I have also tried request.POST to get value but now working.What I exactly want is to get 'count' from JS to my view.But its not happening, Even the 'hello' is not getting printed it's not even related to JS.I'm fairly new to both django and JS so I'm not sure what I'm doing wrong.