Re: a little more help with python server-side scripting
Paul Boddie wrote: > To sum up: > > 1. Copy the three line "CGI with Python" example, save it as > yourfile.py, upload it, test it. If it works, celebrate and move > on to step 2. If it doesn't, move on to step 2 anyway. ;-) > > 2. Copy the Web page example from the Microsoft link, save it > as yourfile.asp and also as yourfile.html, upload them, test > them. If one of them works, celebrate and note down whether > you should be using .asp or .html on the end of your filenames. > If both of them work, celebrate more vigorously! If neither work, > try and tell us what went wrong. Thank you. I'm going to study your response and give it all a try! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > > Well, I appreciate the help. I'm trying to figure it out, but it seems > like with each new post, there is some new technology being mentioned or > new method to do what I'm trying to do. Let's just consolidate what we've learned here. Your provider says that you can serve up two different things; the first one being... bits of Python code that are embedded within an HTML file ... (this being from a message you quoted), although they don't really make themselves totally clear, because they then say... that after mapping .html will no longer be call as normal html file to be loaded on the browser as the IIS server now will parse .html with the Python executable engine. Your user will need to embed the Python coding into each of the .html file in order for it to be load properly on the browser. ...which sounds like ASP to me, noting that the "Python executable engine" is probably the Active Scripting engine which can work with Python. So let's call that the "ASP with Python" route. Now, the other thing they said you could serve up are Python scripts: Save your python script as .py file on the wwwroot and you may call the scripts using http://www.yourdomain.com/yourfile.py What these scripts have to do when they run is to output some text which consists of some headers and the text of a Web page that will appear in your browser (and you can test them yourself before you upload them by seeing if they output the expected stuff when you run them). Let's call this the "CGI with Python" route. > I guess I'm not well-versed > enough in Python to even attempt this kind of thing yet. I didn't > realize it would be this complicated. I guess I hoped it would be as > easy as including some PHP code and letting the server detect the .php > extension and handle it all. I'm going to try to solidify the basics > first, then move on to web programming a little later. Well, guessing at your configuration from what the support people have said, it may be simpler to just test things with the "CGI with Python" option first. So, if you take a CGI program such as one from this page... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52220 ...like this one... #!/usr/bin/python import cgi cgi.test() ...save it as yourfile.py, upload it as instructed above, and then visit your site (also as instructed above), you should see some test output from Python. (Again, you can check the output by running yourfile.py locally and seeing that it prints out some HTML to the screen.) If you want to do the PHP-style thing - the "ASP with Python" option - then you probably need to make a Web page, similar to that described here... http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494 ...save it as yourfile.html (given what they said in their response to you, although most people thought it should be yourfile.asp - why not try both?!), upload it, and then visit your site (as instructed above, but remembering that you're looking for a file called yourfile.html or yourfile.asp instead of yourfile.py). If the yourfile.html thing doesn't work but the yourfile.asp does, then forget about what they said about HTML files and .html and remapping things: just call your "ASP with Python" files names with .asp on the end. To sum up: 1. Copy the three line "CGI with Python" example, save it as yourfile.py, upload it, test it. If it works, celebrate and move on to step 2. If it doesn't, move on to step 2 anyway. ;-) 2. Copy the Web page example from the Microsoft link, save it as yourfile.asp and also as yourfile.html, upload them, test them. If one of them works, celebrate and note down whether you should be using .asp or .html on the end of your filenames. If both of them work, celebrate more vigorously! If neither work, try and tell us what went wrong. Good luck! Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Magnus Lycka wrote: > Listen John. This will be the last time I respond > to this thread, since you just ask more and more > instead of digesting all the information you are > given. Why should we spend time on answers if you > don't read them properly anyway. Well, I appreciate the help. I'm trying to figure it out, but it seems like with each new post, there is some new technology being mentioned or new method to do what I'm trying to do. I guess I'm not well-versed enough in Python to even attempt this kind of thing yet. I didn't realize it would be this complicated. I guess I hoped it would be as easy as including some PHP code and letting the server detect the .php extension and handle it all. I'm going to try to solidify the basics first, then move on to web programming a little later. -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > But isn't this code: > > Response.Write('Python Test') > Response.write('Smaller heading') > > written using ASP instead of Python? Listen John. This will be the last time I respond to this thread, since you just ask more and more instead of digesting all the information you are given. Why should we spend time on answers if you don't read them properly anyway. I understand that you are confused, but you need to analyze the material you have been provided. ASP is not a programming language. The code above shows the Python ASP API. Most ASP developers use VBScript, and since ASP is one of those technologies Microsoft tosses at clueless people, I'm sure many people who use VBScript in ASP don't understand the distinction, and those who hire ASP developers or buy web site development often don't. These guys will probably also think that Sun's language Java and Netscape Corp's JavaScript are the same things too. Clueless. The example is a bit boring of course, since it doesn't show anything except a few calls that probably look almost the same in most languages that can be used in ASP. If there had just been a loop or something... Whatever web tool kit you use, there will be an API that you must learn. An interface for communicating with these mechanisms that provide the web server interface. In the web context, there is some sort of request made from a browser (or spider or whatever) and based on that, the Python script (CGI, ASP, SkunkWeb PSP or whatever) must handle the request (if there are parameters to care about) and produce some kind of response. In a CGI script, you work on a very low level, and need to print content-type headers, error codes etc. In ASP, your API takes care of the details, and you just print the "meat". This abstraction is managed through the Response object. I'm sure you can find plenty of help on the web. Use google. -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Kent Johnson wrote: > > John Salerno wrote: > >> Magnus Lycka wrote: > >> > >>> The other option is ASP. You have been given information about > >>> that already. Be aware that ASP does not imply VBScript. You can > >>> use Python in ASP as long as that's enabled. It seems to be exactly > >>> what you are asking for, so I don't understand why you seem to reject > >>> it. Don't you like the file name endings? > >> > >> > >> Maybe I'm misunderstanding what is meant when you say to use ASP. I'm > >> thinking that it involves having to learn another language (such as C# > >> with ASP.NET), instead of writing my code in Python. Is that not the > >> case? > > > > See http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494 > > > > The last example on this page is exactly what you have been asking for. > > > > Kent > > But isn't this code: > > Response.Write('Python Test') > Response.write('Smaller heading') > > written using ASP instead of Python? Here's a demo script called 'tut1.asp' located in 'site-packages\win32comext\axscript\Demos\client\asp': for i in range(3,8): Response.Write("Hello World!!
" % i) ### and here is 'CreateObject.asp' from the same directory: # Just for the sake of the demo, our Python script engine # will create a Python.Interpreter COM object, and call that. # This is completely useless, as the Python Script Engine is # completely normal Python, and ASP does not impose retrictions, so # there is nothing the COM object can do that we can not do natively. o = Server.CreateObject("Python.Interpreter") Response.Write("Python says 1+1=" + str(o.Eval("1+1"))) Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Maybe I'm misunderstanding what is meant when you say to use ASP. I'm > thinking that it involves having to learn another language (such as C# > with ASP.NET), instead of writing my code in Python. Is that not the case? Nope. Just like CGI, ASP is language agnostic. It's a Microsoft standard for embedding code in HTML pages. Look at the references earlier in the thread and/or google for Python ASP. Of course, the catch here is that your ISP might not have enabled Python as a scripting language on the servers... Finally, it's my impression that your ambition is to use some kind of scripting to get a uniform look and navigation etc in your web pages. This might not require any kind of dynamic web site. In that case I'd suggest that you simply make build some Python tool on your own computer that builds a static version of your entire web site in the safe and free environment of your home. If you want to change something, you simply edit a file at home, rebuild your site and upload the new files. I've built a few sites like that, and if you don't really need to serve anything but static pages, it's probably your best bet. - It'll give you a snappy site. It just serves static pages. - You don't rely on any particular technology from your ISP, they just need FTP etc so that you can upload your files, and a plain web server. - You have the original content at home, so you always have a backup of your web site. - You can use whatever tools you like to create your data without involving your ISP. Personally, I think HTML is a crappy language to write text in. I prefer to use something like reST, see http://docutils.sourceforge.net/rst.html From reST there are convenient tools to get both HTML and PDF documents--good for CVs etc. The standard tool doesn't make room for those custom headers or footers though. There is some help there though. Look here: http://docutils.sourceforge.net/docs/user/links.html -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Kent Johnson wrote: > >> John Salerno wrote: >> >>> Magnus Lycka wrote: >>> The other option is ASP. You have been given information about that already. Be aware that ASP does not imply VBScript. You can use Python in ASP as long as that's enabled. It seems to be exactly what you are asking for, so I don't understand why you seem to reject it. Don't you like the file name endings? >>> >>> >>> >>> Maybe I'm misunderstanding what is meant when you say to use ASP. I'm >>> thinking that it involves having to learn another language (such as >>> C# with ASP.NET), instead of writing my code in Python. Is that not >>> the case? >> >> >> See http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494 >> >> The last example on this page is exactly what you have been asking for. >> >> Kent > > > But isn't this code: > > Response.Write('Python Test') > Response.write('Smaller heading') > > written using ASP instead of Python? No, it's Python code that calls the Write() method on the Response object that is exposed by ASP. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Kent Johnson wrote: > John Salerno wrote: >> Magnus Lycka wrote: >> >>> The other option is ASP. You have been given information about >>> that already. Be aware that ASP does not imply VBScript. You can >>> use Python in ASP as long as that's enabled. It seems to be exactly >>> what you are asking for, so I don't understand why you seem to reject >>> it. Don't you like the file name endings? >> >> >> Maybe I'm misunderstanding what is meant when you say to use ASP. I'm >> thinking that it involves having to learn another language (such as C# >> with ASP.NET), instead of writing my code in Python. Is that not the >> case? > > See http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494 > > The last example on this page is exactly what you have been asking for. > > Kent But isn't this code: Response.Write('Python Test') Response.write('Smaller heading') written using ASP instead of Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Magnus Lycka wrote: > >> The other option is ASP. You have been given information about >> that already. Be aware that ASP does not imply VBScript. You can >> use Python in ASP as long as that's enabled. It seems to be exactly >> what you are asking for, so I don't understand why you seem to reject >> it. Don't you like the file name endings? > > > Maybe I'm misunderstanding what is meant when you say to use ASP. I'm > thinking that it involves having to learn another language (such as C# > with ASP.NET), instead of writing my code in Python. Is that not the case? See http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494 The last example on this page is exactly what you have been asking for. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Magnus Lycka wrote: > The other option is ASP. You have been given information about > that already. Be aware that ASP does not imply VBScript. You can > use Python in ASP as long as that's enabled. It seems to be exactly > what you are asking for, so I don't understand why you seem to reject > it. Don't you like the file name endings? Maybe I'm misunderstanding what is meant when you say to use ASP. I'm thinking that it involves having to learn another language (such as C# with ASP.NET), instead of writing my code in Python. Is that not the case? -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Ok, seems like the verdict is that the server doesn't have mod_python > nor does it detect the .psp extension. It can, however, detect the .py > extension. But does this mean I can simply include Python code in my > HTML files, and then give my HTML files a .py extension? I don't know > how to test this because I don't know how to write inline code yet. Is > it something like: No, you can't do that. From your descriptions, it seems that Python is set up as a CGI language, just as one would use Perl etc. This means that if you have an URL ending with x.py, the web server will do these things when you request this URL from the server: 1. Set up a number of environment variables which are useful for the python script it will call. Very important if the URL was invoked from an HTML form, which I don't suspect will happen on your site. 2. Invoke Python with your script. Basically it should call python.exe -u x.py 3. Read the data that x.py sends to stdout, e.g. print statements etc. Provided that this output looks ok, it will send it to the browser, otherwise it will typically send ERROR 500 (internal server error) instead. You were given a CGI script already that printed out environment variables. I got the impression that you tried that out. If you set the environment variables shown by that CGI script using the SET command at a Windows command prompt, and then execute your python script at that command prompt, it has to print something like Content-type: text/html blah blah whatever There is no magic beyond this. Try renaming an HTML file to .py and invoke Python with that. It will just say SyntaxError! The change isn't big though! You just need to make the HTML content into a big string (surround it with """) and print the content-type line, an empty line and this big string, and you have a start. You have already been provided with all the information you need. I think you need to look closely at the information Paul and several others have given you instead of just asking more questions, and really start using it. You won't get anywhere otherwise. The other option is ASP. You have been given information about that already. Be aware that ASP does not imply VBScript. You can use Python in ASP as long as that's enabled. It seems to be exactly what you are asking for, so I don't understand why you seem to reject it. Don't you like the file name endings? -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Paul Boddie wrote: > > > No, it means that you either write Python programs which produce pages > > as output, according to the CGI specification, or that you embed Python > > code inside ASP files, as described in the above document. > > > I haven't used ASP, and I've been working hard to remove from my memory > > any trace of similar systems (eg. JSP), but I imagine that if you want > > to include normal Python programs inside ASP files, there may be a way > > of using some kind of "include" directive. Take a look at the above > > document for some ideas. > > Why do you mention ASP though? Can't this be done without it? You mean, can't you just write normal HTML files, add some kind of "include" directive, call them something ending in .html, and then have the server produce a combination of normal HTML and the output from Python code? Well, not really, since that (apart from the .html extension on the filename) is a description of what ASP is about, more or less. But yes, if you want to run Python code without doing strange things with ASP files, then just write a program (not a Web page, but an actual Python program) as described in the Microsoft document (or virtually any introduction to CGI with Python), upload it into the appropriate folder/directory with a filename ending in .py and test it out! See this recipe for other examples (found using the search text "CGI Python" with Google): http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52220 Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > > Ok, seems like the verdict is that the server doesn't have mod_python > nor does it detect the .psp extension. It can, however, detect the .py > extension. But does this mean I can simply include Python code in my > HTML files, and then give my HTML files a .py extension? No. [...] > > ? They say: > > "Please note that you may map .py to .html extension. However, if you > set this mapping, .html will not work with the normal html tags anymore." > > But I don't know what this means about 'mapping' the extension and what > it means that html tags won't work anymore. John There is a configuration section in the IIS management tool (inetmgr.exe) called 'Application Mappings' which maps file extensions to applications. For example, on my (WinXP) machine I have: .aspx --> C:\WINDOWS\Microsoft.NET\Framework\v1.14322\aspnet_isapi.dll .asp --> C:\WINDOWS\system32\inetsrv\asp.dll .php --> C:\Program Files\PHP\Php51\php-cgi.exe among others. So if IIS receives a request for a url with one of these extensions it passes that request on to the relevant program. You could map '.py' to 'python.exe %s %s' but any '.py' files would have to be pure Python. IIS doesn't need any help with standard, static .html requests, it can serve those itself. It may be possible to map '.html' to any of the three applications above and still have static HTML pages function identically (even if this would create a pointless overhead ), however you couldn't map '.html' to 'python.exe' and expect anything meaningful - there is nothing like 'python-cgi.exe' that understands HTML with or without inlined python code. Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Paul Boddie wrote: > No, it means that you either write Python programs which produce pages > as output, according to the CGI specification, or that you embed Python > code inside ASP files, as described in the above document. > I haven't used ASP, and I've been working hard to remove from my memory > any trace of similar systems (eg. JSP), but I imagine that if you want > to include normal Python programs inside ASP files, there may be a way > of using some kind of "include" directive. Take a look at the above > document for some ideas. Why do you mention ASP though? Can't this be done without it? -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > John Salerno wrote: > > > Unfortunately, I don't completely understand what it is I need to do > > now. Where do I put the path they mentioned? And what do they mean by my > > script path? > > Ok, seems like the verdict is that the server doesn't have mod_python > nor does it detect the .psp extension. It can, however, detect the .py > extension. >From what I understand of the situation, noting that I haven't used IIS with Python at all as far as I remember (and it'd be about six or seven years ago if I did), you're using Windows hosting where .py files get special treatment - ie. they don't get served up as text files but are executed somehow - and that this is probably configured by your provider as described in this document (found via Google using the search text "IIS Python"): http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494 > But does this mean I can simply include Python code in my > HTML files, and then give my HTML files a .py extension? No, it means that you either write Python programs which produce pages as output, according to the CGI specification, or that you embed Python code inside ASP files, as described in the above document. > I don't know how to test this because I don't know how to write inline code > yet. Is > it something like: > > <%@ include file=something %> I haven't used ASP, and I've been working hard to remove from my memory any trace of similar systems (eg. JSP), but I imagine that if you want to include normal Python programs inside ASP files, there may be a way of using some kind of "include" directive. Take a look at the above document for some ideas. > ? They say: > > "Please note that you may map .py to .html extension. However, if you > set this mapping, .html will not work with the normal html tags anymore." > > But I don't know what this means about 'mapping' the extension and what > it means that html tags won't work anymore. I think they're just trying to say that if you decide that your Python programs should have a .html extension and still be executed as Python programs, don't expect the server to serve up HTML pages any more. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Unfortunately, I don't completely understand what it is I need to do > now. Where do I put the path they mentioned? And what do they mean by my > script path? Ok, seems like the verdict is that the server doesn't have mod_python nor does it detect the .psp extension. It can, however, detect the .py extension. But does this mean I can simply include Python code in my HTML files, and then give my HTML files a .py extension? I don't know how to test this because I don't know how to write inline code yet. Is it something like: <%@ include file=something %> ? They say: "Please note that you may map .py to .html extension. However, if you set this mapping, .html will not work with the normal html tags anymore." But I don't know what this means about 'mapping' the extension and what it means that html tags won't work anymore. -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > After a little more investigation, this seems to be just one > implementation of PSP. I need to just figure out how to get 'regular' > PSP working for me, or if it's even possible on a Windows 2003 server. I don't think there is such a thing as "regular PSP". If they've enabled Python as a windows scripting language, you can use Python instead of VBScript or JScript in ASP. Another option might be http://spyce.sourceforge.net/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Sybren Stuvel wrote: > I wouldn't know, never used Python ;-) So far, me neither. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno enlightened us with: > That sounds like just what I want, except do I have to write my code > in Jython? Can't I just use regular Python? I wouldn't know, never used Python ;-) Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Sybren Stuvel wrote: > >> Check out PSP. > > I found a PSP website that said this: > > - > In general, PSP pages are like normal HTML files with two exceptions: > > 1. They always have a .PSP file extension > 2. They can have JPython code embedded in them > - > > That sounds like just what I want, except do I have to write my code in > Jython? Can't I just use regular Python? After a little more investigation, this seems to be just one implementation of PSP. I need to just figure out how to get 'regular' PSP working for me, or if it's even possible on a Windows 2003 server. -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Sybren Stuvel wrote: > Check out PSP. I found a PSP website that said this: - In general, PSP pages are like normal HTML files with two exceptions: 1. They always have a .PSP file extension 2. They can have JPython code embedded in them - That sounds like just what I want, except do I have to write my code in Jython? Can't I just use regular Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > The python installation on our windows hosting is not configured as > mod_python. Perhaps you can switch to linux hosting instead? If they have mod_python in that environment, you can use Python Server Pages, and whatever tools you use, there is much better support for Apache than for IIS in Python (and many other) web development tools. After all, Apache has almost 70% of the web server share, and IIS has about 20%... http://news.netcraft.com/archives/web_server_survey.html For mod_python's PSP support, see http://www.modpython.org/live/current/doc-html/pyapi-psp.html -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Dennis Lee Bieber wrote: > On Wed, 22 Feb 2006 20:43:38 GMT, John Salerno > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > >>Does that answer the question about active scripting language? > > > Slipping in... It sure sounds to me like they have Python as a pure > CGI language. > > That is: > You must reference the script with a URL having .../script.py (and > arguments will possibly be sent appended to this, but should have been > parsed out and become part of the standard CGI environment). If you want existing links to continue to work, you can simply place HTML redirects in the current HTML files, so that they invoke the proper Python CGI script, i.e. somepage.html should contain a redirect to /my_cgi.py?page=somepage I've roughly described in a previous posting how my_cgi.py should work. Just let it suck in the file with the 'somepage' content, and add the header and footer stuff. You'll find Python CGI tutorials on the net, and the library reference chapters on cgi and cgitb will also help. Start by enabling cgitb... -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Steve Holden wrote: > OK, what you need to ask them is whether they have installed Python as > an Active Scripting language. If they have then you can use it pretty > much like VBscript. Here's there latest: -- Please note that it is possible for the server to recognize bits of Python code that are embedded within an HTML file. However, it will need a custom mapping on the domain for mapping .html to the Python executable on the server. But note that after mapping .html will no longer be call as normal html file to be loaded on the browser as the IIS server now will parse .html with the Python executable engine. Your user will need to embed the Python coding into each of the .html file in order for it to be load properly on the browser. Does that answer the question about active scripting language? -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > John Salerno wrote: > >>I contacted my domain host about how Python is implemented on their >>server, and got this response: > > > Uh, okay, I asked a related question to them and now I got this: > > > Hello John, > > There are some corrections based on last reply. > > The python installation on our windows hosting is not configured as > mod_python. Howevet, it is directly map with a website extensions > mapping in IIS. Save your python script as .py file on the wwwroot and > you may call the scripts using http://www.yourdomain.com/yourfile.py > > If you have any enquiries, please do not hesitate to contact. > > Best regards, > > Mackenzie S. > Support Executive > --- > > Does that really change anything? > Well, it means that PSP is out, unfortunately. > What I had asked was if I could just embed Python code within my HTML > files, like you do with PHP, but they didn't address that yet. OK, what you need to ask them is whether they have installed Python as an Active Scripting language. If they have then you can use it pretty much like VBscript. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno enlightened us with: > What I had asked was if I could just embed Python code within my > HTML files, like you do with PHP, but they didn't address that yet. Check out PSP. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > I contacted my domain host about how Python is implemented on their > server, and got this response: Uh, okay, I asked a related question to them and now I got this: Hello John, There are some corrections based on last reply. The python installation on our windows hosting is not configured as mod_python. Howevet, it is directly map with a website extensions mapping in IIS. Save your python script as .py file on the wwwroot and you may call the scripts using http://www.yourdomain.com/yourfile.py If you have any enquiries, please do not hesitate to contact. Best regards, Mackenzie S. Support Executive --- Does that really change anything? What I had asked was if I could just embed Python code within my HTML files, like you do with PHP, but they didn't address that yet. -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Steve Holden wrote: > Note that purists might suggest this isn't the best way to use Python on > the web. If it gets you where you want to be, feel free to ignore them :-) Thanks for the info. Basically I don't plan to do big stuff with Python on the internet (at least not right now while I'm still learning the language). I already know how to use a PHP include, so I could just keep doing that, but I figure since I'm learning Python, I might as well start using it wherever I can, assuming that it is okay to use it this way. -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Steve Holden wrote: > > >>If the script ran, you will now know waht version of Apaceh you're >>running with! > > > Well, the script did seem to run, but I'm still not sure if this is what > I'm ultimately after. This allows me to run Python script files, which > is good, but what I really want to do is write bits of Python code in my > HTML files (as a means to include headers and footers, for example). So > these bits of Python code will basically be like a PHP include() > function that calls another HTML file which contains the header/footer > HTML to insert into the calling file. This type of situation doesn't > involve calling external Python scripts. > > Maybe I can just try this also and see if it works, but I don't know the > code to use to write such an include statement. What would the > equivalent of this be in Python: > > > > Thanks. There are various ways you can do this, each of which depends on having a particular framework in place. Since your web service provider tells you that mod_python is available it's likely that you'll be able to use PSP (one of several beasts known as "Python Server Pages"). This is briefly described (for a flavor of the technology) in http://www.python.org/pycon/dc2004/papers/14/ by the author of mod_python. If you like what you see then take a look at the full mod_python documentation, at http://www.modpython.org/live/current/doc-html/ Note that purists might suggest this isn't the best way to use Python on the web. If it gets you where you want to be, feel free to ignore them :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Steve Holden wrote: > If the script ran, you will now know waht version of Apaceh you're > running with! Well, the script did seem to run, but I'm still not sure if this is what I'm ultimately after. This allows me to run Python script files, which is good, but what I really want to do is write bits of Python code in my HTML files (as a means to include headers and footers, for example). So these bits of Python code will basically be like a PHP include() function that calls another HTML file which contains the header/footer HTML to insert into the calling file. This type of situation doesn't involve calling external Python scripts. Maybe I can just try this also and see if it works, but I don't know the code to use to write such an include statement. What would the equivalent of this be in Python: Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Steve Holden wrote: >> Where does this line go? Just at the top as well? > > Nope. I presume you can log in to your web server using ssh or telnet or > similar. In which case you do so. Then use the commands > > cd {wherever}/cgi-bin > chmod +x test.py > > to make the script executable, and therefore recognised as a proper > script by Apache. I'm afraid I still don't understand. I guess this step isn't necessary, since the script seemed to run anyway, but I'd like to know this anyway. The way I log into my server space is by an FTP program, so I don't see an occasion to actually *type* in any kind of commands. -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Steve Holden wrote: > > >>Fortunately they've given you the information you need to run CGI >>scripts. Try installing this script in your cgi-bin directory as test.py >>(you may have to set it executable): > > > Thank you! I desperately needed to test it, and that seemed to work. I > didn't have to make it executable though. I wonder why? Probably because the cgi-bin directory is specially marked to contain executables. If you drop the script in another directory you will almost certainly just see the source of the script. Making it executable *might* cause it to run, but that would depend on exactly how your server is configured. Certainly my sites all have a line like ScriptAlias /cgi-bin/ "c:/apache/cgi-bin/" in the httpd.conf file. ScriptAlias tells Apache that the files in the directory are scripts. The first argument is the address in web-space, the second the address on disk. You'll find you can affect *some* configuration items by creating files called .htaccess in your web content directories, but that's a ways down the road yet. If the script ran, you will now know waht version of Apaceh you're running with! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > Ben Cartwright wrote: > > >>>The script can be given a executable mode, or permission, using the >>>chmod command: >>> >>> $ chmod +x myscript.py >> >>And this answers your second. Your host needs to know the path to your >>script so they can use chmod to make it executable. > > > Where does this line go? Just at the top as well? Nope. I presume you can log in to your web server using ssh or telnet or similar. In which case you do so. Then use the commands cd {wherever}/cgi-bin chmod +x test.py to make the script executable, and therefore recognised as a proper script by Apache. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Steve Holden wrote: > Fortunately they've given you the information you need to run CGI > scripts. Try installing this script in your cgi-bin directory as test.py > (you may have to set it executable): Thank you! I desperately needed to test it, and that seemed to work. I didn't have to make it executable though. I wonder why? -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
Ben Cartwright wrote: >> The script can be given a executable mode, or permission, using the >> chmod command: >> >> $ chmod +x myscript.py > > And this answers your second. Your host needs to know the path to your > script so they can use chmod to make it executable. Where does this line go? Just at the top as well? -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > I contacted my domain host about how Python is implemented on their > server, and got this response: > > --- > Hello John, > > Please be informed that the implementation of python in our server is > through mod_python integration with the apache. > > These are the steps needed for you to be able to run .py script directly > from browser for your webpage: > > 1. Please use the below mentioned path for python: > #!/usr/bin/env python > > Furthermore, update us with the script path, so that we can set the > appropriate ownership and permissions of the script on the server. > > If you require any further assistance, feel free to contact us. > --- > > Unfortunately, I don't completely understand what it is I need to do > now. Where do I put the path they mentioned? And what do they mean by my > script path? Don't worry, it looks as though they don't completely understand either :-) Fortunately they've given you the information you need to run CGI scripts. Try installing this script in your cgi-bin directory as test.py (you may have to set it executable): #!/usr/bin/env python # import os print "Content-Type: text/plain" print for t in os.environ.items(): print "%s=%s" % t If it runs when you access http://yourdomain/cgi-bin/test.py it looks like you're good to go! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: a little more help with python server-side scripting
John Salerno wrote: > I contacted my domain host about how Python is implemented on their > server, and got this response: > > --- > Hello John, > > Please be informed that the implementation of python in our server is > through mod_python integration with the apache. > > These are the steps needed for you to be able to run .py script directly > from browser for your webpage: > > 1. Please use the below mentioned path for python: > #!/usr/bin/env python > > Furthermore, update us with the script path, so that we can set the > appropriate ownership and permissions of the script on the server. > > If you require any further assistance, feel free to contact us. > --- > > Unfortunately, I don't completely understand what it is I need to do > now. Where do I put the path they mentioned? And what do they mean by my > script path? The Python tutorial should fill in the blanks (http://www.python.org/doc/tut/node4.html): > 2.2.2 Executable Python Scripts > > On BSD'ish Unix systems, Python scripts can be made directly executable, > like shell scripts, by putting the line > > #! /usr/bin/env python > > (assuming that the interpreter is on the user's PATH) at the beginning > of the script and giving the file an executable mode. The "#!" must be > the first two characters of the file. On some platforms, this first line > must end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or > Windows ("\r\n") line ending. Note that the hash, or pound, character, > "#", is used to start a comment in Python. This answers your first question. Put the #! bit at the top of your .py script. This way the web server will know how to run the script. > The script can be given a executable mode, or permission, using the > chmod command: > > $ chmod +x myscript.py And this answers your second. Your host needs to know the path to your script so they can use chmod to make it executable. --Ben -- http://mail.python.org/mailman/listinfo/python-list