Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access data from local storage in Django views?

How do I access the value of key "store1" inside local storage in my Django views.py??

HTML, in Django templates --> index.html

-User will key in input and button will activate local storage function

<input type="text" id="firstID">
<button onclick="myFunction()">LocalStorage</button>

Javascript

-User input is saved in variable which is used to for local storage

var siteName = document.getElementById('firstID');
function myFunction() {
  localStorage.setItem('store1', siteName.value);
like image 835
Royston Teo Avatar asked Mar 06 '23 10:03

Royston Teo


1 Answers

LocalStorage is client storage in your browser. Your *.py files will be executed in server. So you can not access them directly. You can save them as cookie, or put them to server via ajax request.

like image 51
Bendy Zhang Avatar answered Mar 16 '23 19:03

Bendy Zhang