I have tried searching online like crazy with no avail. PHP is as simple as naming the file .php and writing PHP. I know people say it's that simple for Python, but I have found no useful guides in setting it up. I merely want to practice Python on my computer via WAMP or another alternative. I am on Windows Vista.
I cannot get .py files to execute correctly. The actual text:
print("Hello!")
Appears just as that rather than "Hello!". I don't know what to do to make it actually work in my browser.
Any help or pointing towards guides would be greatly appreciated.
PHP does not execute in the browser. It is executed on the server side then the output is sent by the web server to the browser.
If you want a simple way to use Python to process web requests take a look at web.py (http://webpy.org).
Your server should handle Python code. Take a look at framework Django. And as for servers I can suggest you http://webfaction.com
Related
just a general question.
I have written some Python codes in Spider. In my code, I use sql command to pull data from ssms then use Python to manipulate them. Now I want to implement my codes on a webpage or other online sources so other can run them. How would be possible? Any thought would be appreciate :) Thanks!
P.S I'm a PC user not MAC
Here's a link to a list of Python-based web frameworks:
https://wiki.python.org/moin/WebFrameworks
I know people who like Flask (http://flask.pocoo.org/), and it has some thoughtful-looking Windows installation instructions here: http://flask.pocoo.org/docs/0.12/installation/#installation.
Also, you might also look at the Python library pyodbc to directly make your queries if I understand you right that you're using sqlcmd.
I've got a python script that I want to build a locally-hosted web gui app for, so I can use the modern styling and tools available to web apps.
The scripts I'm running take a while to process, and I want to update the web app with visual updates, or at least something akin to what the console sees when using print() in python.
My initial hosting efforts have been based on this tutorial, and I tried out the methods in this answer to try and get data to update in a streamed fashion, but the pages only showed once the entire script was finished.
I'm wondering whether web.py could help me?
Any guidance, or even the right terms to google would be appreciated. Thanks.
--
Update: I've been reading up on node.js (something I've failed to do for years..) and, please correct me if I'm wrong, but it seems like it could be the answer. I'm even considering re-writing my original functions into node.js given the existence of this serial comms library
I want to run a python file in the web I have in a GitHub repository. Is it possible to do this?
And by running in the web, I mean putting #!/usr/bin/python and print 'Content-type:text/html\n in the first two lines.
In general this is not possible, Github (pages) serves only static content (ex: HTML, CSS, JS). If you want python to run (ex generate dynamic content) you need a web server capable of running python (your browser were the contents of GitHub Pages get downloaded and run can't do it).
That said there are experimental ways of running subsets of python in the browser. Take a look for a example at this question.
If you truly want to generate a complete HTTP response via standard output, then start by reading about CGI and Python's standard cgi module. You'll also need to have access to a CGI-compatible web server, perhaps running on a virtual host.
However, CGI is quite obsolescent as a way to produce dynamic output for the web. #jjwon's suggestion to look at Python-based web application frameworks like Flask is a good one.
I'm thinking if there already is some sort of online live python console (web-based) with open source code available. Anyone know of anything?
It would be really useful to have console in Django admin (like running python manage.py shell on the server's terminal), so it would be great to have django/any wsgi aplication, that can be used to enable web based live console access.
Thanks
You're looking for the Werkzug debugger.
http://werkzeug.pocoo.org/
http://werkzeug.pocoo.org/docs/debug/
It's got an interactive javascript based in-browser debugger for your WSGI projects, among many other great tools. Fantastic stuff.
For Django specifically, there's also RunServerPlus, which is part of the django-extensions package.
https://github.com/django-extensions/django-extensions
You should check out Python Anywhere. You can run python web apps, you get an SQL database, and you get a bash shell in your browser.
Have a look at python shell from Google. There's a link to source code at the top. Loading Django environment into it might be not very easy but I believe it's possible.
I'm not sure if this meets your desire but you might take a look at Chrome extension : https://chrome.google.com/webstore/detail/gdiimmpmdoofmahingpgabiikimjgcia
There is a great website called Codecademy. It teaches the fundamentals of Python, Ruby, Javascript, and HTML/CSS.
They also have online consoles for each of the languages they teach, excluding HTML/CSS. This website is Codecademy Labs. Codecademy Labs has a console you can type directly in, and an editor that displays output in the console. I hope that this helped you find what you were looking for!
My goal is to use to make it easy for non-programmers to execute a Python script with fairly complex options, on a single local machine that I have access to. I'd like to use the browser (specifically Safari on OS X) as a poor man's GUI. A short script would process the form data and then send it on to the main program(s).
I have some basic examples of python scripts run using the built-in Apache server, by clicking submit on a form whose html is th:
e.g. here. What I want to do now is do it without the server, just getting the form to invoke the script in the same directory. Do I have to learn javascript or ...? I'd be grateful for any leads you have. Thanks.
It doesn't make sense -- what a browser does when it submits a form by definition is to make a request to a web server.
If all that's going on is that you don't want to be running Apache, you could hook something simple up using the CGIHTTPServer class that's provided as part of the Python Standard library.
If you don't want a server process at all, and you're using a suitably modern browser, you may want to look at using HTML5 local storage, but that's not a Python solution.
Well, there always has to be some kind of "server" involved to communicate over HTTP. You could have a python script listening on port 80 on your machine, that in turn runs the scripts specified with the form's action attribute.
You won't get away without some sort of server, I'm afraid.
PS: There are already a couple of good minimalistic python HTTP servers that would do the trick. Just google for it.
Regards, aefxx
Pyjamas Desktop will allow you to deploy a browser-based desktop application.