Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass variable to a python cgi script
    primarykey
    data
    text
    <p>What I want to do is have a single python program in cgi-bin that is executed by each of many pages on the site, and displays a line of HTML on each page that is different for each file, but keyed to the URL of that file on the site.</p> <p>I know how to get the URL using javascript (e.g. on <a href="http://constitution.org/cs_event.htm" rel="nofollow">http://constitution.org/cs_event.htm</a> ):</p> <pre><code>&lt;script language="javascript"&gt; var myurl = document.location.href; document.write(myurl); &lt;/script&gt; &lt;br&gt; &lt;script language="javascript"&gt; var myurl = document.location.href; document.write("&lt;A href=\"" + myurl + "\"&gt;" + myurl + "&lt;\/A&gt;"); &lt;/script&gt; </code></pre> <p>And I know how to create a link that opens a page to execute the .py script when one clicks on it:</p> <pre><code>&lt;a href="http://constitution.org/cgi-bin/copy01.py?myurl=myurl"&gt;Here&lt;/a&gt; </code></pre> <p>Here is the python script so far:</p> <pre><code>#!/usr/bin/env python # This outputs a copyright notice to a web page import cgi print "Content-Type: text/html\n" form = cgi.FieldStorage() thisurl = form.getvalue("myurl") print """ &lt;html&gt;&lt;head&gt;&lt;/head&gt; &lt;body&gt; """ print """ Copyright &amp;copy; 1995-2011 Constitution Society. Permission granted to copy with attribution for non-profit purposes. """ print """ &lt;/body&gt;&lt;/html&gt; """ print thisurl </code></pre> <p>But it is not so obvious how to pass the variable value to the .py script, and have it automatically display the URL of that page the way the javascript does, or display a line of HTML that it will get from a dictionary in which the URLs are the keys and the HTML lines are the data.</p> <p>Ultimately, I want to be able to generate, using a single .py script, all the footer content of each page, that can be maintained from a single file that I can edit to make changes that propagate everywhere.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload