title: Loading timestamp upon page load and comparing it to timestamp upon form submit
body: <p>I've developed an anti-spam time trap in my app (yes I know it's not going to be 100% effective, but it's a stopgap measure) that does this:</p>
  
  <p>1) When a page is loaded, populate a hidden input with a timestamp using JavaScript:</p>
  
  <pre><code>var timestamp = new Date().getTime() / 1000;
  </code></pre>
  
  <p>2) When the form is POSTed, use the Python view to check this timestamp against current time -- if it's been less than 5 seconds since the page was loaded, bounce back an exception:</p>
  
  <pre><code>import datetime
  
  feedback_timestamp = request.POST['feedback_timestamp'].strip()
  current_timestamp = datetime.datetime.now().timestamp()
  
  if current_timestamp - float(feedback_timestamp) &lt; 5:
      raise Exception("Submitted too quickly after loading!")
  </code></pre>
  
  <p>This works fine on my local development server (i.e. it forces you to wait 5 seconds or else it throws the exception). However, I noticed that once I load it on my production server, the timestamps were about 30 seconds off from one another, even if I submitted the form immediately after loading. It appears that the JavaScript function grabs the time from the local user, while the Python code grabs it from the server so, if they're out of sync, it won't trigger properly.</p>
  
  <p>My question is: how do I grab the initial timestamp from the server, instead of the local machine? Is there a JavaScript function that does this? Or do I need to populate the hidden input using the Python backend instead?</p>
  
  <p>If the latter, things are a bit complicated because this is all being done in my base.html, which is never loaded directly by any of my views (i.e. it's used to extend numerous other views that I use). How would I pull a value from the Python backend without using a view associated with the page?</p>