Python not working in web browser [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am not able to execute python files in web browser but file can be executed from SHELL terminal.
For Example:
I have created a file under public_html/index.py with following code
#!/home/explore/bin/python
print "Content-Type: text/html\n"
print "Hello World!"
But when I am opening this file in browser, its just coming in simple TEXT.
Note: The index.py file is working fine, When I am trying to run this file by giving absolute path for both files in SHELL terminal using following command
Error: /home/explore/bin/python index.py This gives me error file not found
Correct: /home/explore/bin/python /home/explore/public_html/index.py Works nicely in shell terminal
Please Help, and tell what should i do?

it's normal. The browser don't understand your python file. A browser can handle JavaScript, HTML, ... but no python files. This is why you will have plaintext file.
You need to create an HTTP server that will handle the python file.
You can check around: apache2 and mod_python, django (which is a framework written in python).
Another way would be to write your own HTTP Server in python and connect to it through the browser.
Then you can implement whatever you like. Try to do it by searching : "Python http server" in goodle. There is million of tutorials and guides on the web for that.
Have a nice day.
Kursion
Ressources:
Django guides:
https://docs.djangoproject.com/en/dev/intro/install/
http://hackercodex.com/guide/python-install-django-on-mac-osx-lion-10.7/
http://mirkobonadei.wordpress.com/2010/01/25/install-python-and-django-on-windows/
and so on

Related

How to export python files for other use? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am looking to export some .py files so I can include them in a website. I am not sure any method to export the files however. Could someone please link some useful information or explain a procedure so the files can be executed using buttons on a website (particularly a HTML site)?
You can use UWSGI as an intermediary between your Python files and nginx (as a web server). But this is not as easy as executing php files, since the php executor comes with any web server. Or call python files as external programs from your existing site.
if your are looking to import function or classes in a file and use them in another file or project, then this might be what you are looking for imports in python

Web2py launch script [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need a launch script which has access to "db" and other web2py modules. This script must be running constantly. I know that Web2py has launch parameters from which you can run python files in the web2py enviroment, but i don't know how that works. Can this parameter solve my problem and if so, how do I go about it? Thanks!
Look at section 4.17.1 of the web2py manual (or Google "web2py cron").
You can run a script on startup of web2py by registering it in the crontab file as:
"#reboot web2py *scripts/myscript.py"
web2py should be the username that it will run as, which should be the same as what web2py runs as. In my setup I have a user named 'web2py' to run the app.
The asterix before scripts/myscript.py indicates that you want to run the script in the web2py environment.
Keep in mind that you run the risk of locking issues if your script is trying to use the database at the same time as the normal web2py process.

How to run simple python script on web [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What is the simplest way of running a python script on the web?
I've been learning to use python to create really simple scripts that scrape the web and represent that data as HTML that can be cut-and-pasted into our CMS.
I'd like to share the technology with my colleagues without forcing them to install python on their machines and thought the web would be a great solution.
I've seen solutions ranging from Django to Flask, Tornado to Python On Wheels but I'm just getting overwhelmed by lots of server-speak.
Can anyone suggest a framework that makes it simple for newbies to get started and develop as I get more experience?
Secondary question: how easy - or not - would it be to have modules available to bolster the toolkit?
Have you considered trying Google App Engine. Some details here: https://developers.google.com/appengine/docs/python/
If you are only interested in scraping maybe scraperwiki is something for you. It allows you to build scrapers in python and it handles the storage.
And otherwise maybe this question has the answer.
You can set it up in apache with WSGI quite easily.. although not sure which OS you're runnin on the server.
For Ubuntu 12.04:
First, install Apache's module:
sudo aptitude install libapache2-mod-wsgi
Then, restart Apache:
sudo service apache2 restart
Then you can add a simple example program to test; install it in /usr/lib/cgi-bin/ then, just run from http://your-domain/cgi-bin/your-script.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
print "Content-Type: text/html" # needed to indicate that the content is HTML
print # blank line, end of headers, don't remove
print "Hello World!"
Hope that helps!

Why my Django server not work suddenly? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am woking on Ubuntu 12, python2.6 and Django1.2.x which is my test server.
And I run a Django project on my test server using below command:
python manage.py runserver 0.0.0.0:8000
The server can work for most time(I let it run on 7X24 for other teammate to access it), but sometime it would suddenly not work:
Browser shows me that "server not available" when I try to access it.
And of course, the test server cannot get any request from my frontend, and no error throws on server side.
All will back to OK once I using my django project and run it again.
now I have 2 question:
Why does this issue happend?
How can I develop a shell script to detect this situation?
Actually, it looks like you're trying to use Django development for production purposes. There may be a lot of explanations, like apparmor config, or limitation of single-threaded server, but the problem doesn't worth investigating. Just install Apache2, or Nginx, or uwsgi, and that's it, you have good and stable server without shell watchdogs and other kludges. It would probably take about the same time as posting to SO

Beginner advice on how to use FTP or SSH? (django) [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm in the midst of trying to get my first website up and running all of the sudden I get to the point where I need to get my file online and I have zero idea on how to do that. I thought it would be as easy as selecting your files and clicking upload but so far it has not been that easy. Currently I'm using djangoeurope.com. So if anyone has experience with that site that would help extra.
If you have ssh access, confirm that it's working by using
ssh [username]#[hostname]
If you can log in using ssh, you can use scp to put your files onto the server (log out of the remote server first)
scp [local_file_path] [hostname]:[remote_file_path]
For example,
scp local.txt files.server.com:/home/local.txt
This should work from a terminal on a Mac or Linux system. If you're on Windows, you should look at WinSCP
If you sign up with Heroku, your deployment process is very straightforward, and as an added bonus you do not have to deal with FTP and server configuration.
There are different tools for FTP and SSH file transfer. Which one is best for you depends on your environment (e.g. operating system) and your needs (do you want a graphical or command line interface?). But basically it's always a program you run on your machine that connects to a server to upload files. You don't do anything through a web site (except finding out which server to connect to and maybe setting up an account / password).

Categories