Cherrypy - prevent browser "prefetch"?

Tim Chase python.list at tim.thechases.com
Mon Dec 1 21:50:00 EST 2014


On 2014-12-01 13:14, Israel Brewster wrote:
> On Dec 1, 2014, at 12:50 PM, Ned Batchelder <ned at nedbatchelder.com>
>> The way to indicate to a browser that it shouldn't pre-fetch a
>> URL is to make it a POST request.
> 
> Ok, that makes sense. The only difficulty I have with that answer
> is that to the best of my knowledge the only way to make a HTML
> link do a POST is to use the onclick function to run a javascript,
> while having the "link" itself point to nothing.

Well, generally one would use a form where the method=POST and then
the button/input submits it:

 <form action="/path/to/my/url/" method="POST">
  <input type="submit">This is an input<input>
 </form>

or

 <form action="/path/to/my/url/" method="POST">
  <button type="submit">This is a <strong>button</strong></button>
 </form>

The advantage of a <button> is that it can contain rich content
(other markup) while an <input type="submit"> can't.

To do a POST via an <a> tag, you do need (as you mention) to do some
ugly jiggery with JavaScript, but tends to break the mental model.
You should be able to style a <button> element to look much like a
link if you find the visual effect of a <button> unpleasant.

-tkc





More information about the Python-list mailing list