kmcodes
kmcodes

Reputation: 857

Running a python script on my hosting

I am a newbie to web development and Python. Since I dont have the vocabulary to ask the exact question, here is a summary of what need to do:

Can someone tell me If i need to create an html file, and if yes how to get it to point to the python script The domain folder has wordpress installed. My hosting is dreamhost shared hosting

The script is there below:

#! /usr/bin/python

print 'Content-type: text/html'
print ''
print 'Hello, World!

Upvotes: 6

Views: 10886

Answers (3)

Muhammad Taqi
Muhammad Taqi

Reputation: 5424

Heroku is a good place to host and python scripts.

Pre-req

pythonscripts.py
procfile
requirements.txt

and After add, commit and push the scripts to heroku app. Just run the following command on terminal to run the scripts.

heroku run python your_scripts.py

More if you want to run this scripts on a schedule timing. then heroku provides lots of adds-on. just search it on heroku

Upvotes: 3

Alium Britt
Alium Britt

Reputation: 1316

Usually you'd need to put your python script under the /home/username/bin/ folder. I'm not sure if your particular webhost actually allows you to run your Python script outside of the /bin folder (normally this is not the case), but if yes then you can substitute the /pyscripts folder.

The URL would look something like this: www.domain.com/bin/mypythonscript.py

Or with the pyscripts folder (if possible with your webhost): www.domain.com/pyscripts/mypythonscript.py

You don't need to create an HTML file as the first content line that you print in your Python script is telling the user's browser to display the output of the script like an HTML file. You simply type the URL to your python script into your browser and then the server runs the script and outputs it as a text/HTML file, which your browser then reads and displays.

Also, don't forget - you need to grant execute/read/write permission to your Python script file after you upload it to the correct folder on your webhost server or it won't run at all. Usually this is done through your upload utility like Filezilla or using a shell command like chmod.

Upvotes: 2

Raja Simon
Raja Simon

Reputation: 10305

Well dream host support python. Check if they are providing shell access deployment. All you need is create .py file and run it.

Then consider to use Django or Jinja2 like framwork. Its easy for creating web application

Upvotes: 1

Related Questions