I want to write a program in python which can read the files under a directory and can show them as hyperlink in a html page created by python program dynamically , can anyone please suggest i am newbie for python.
Quick hack using SimpleHTTPServer
Go to the directory, you want to have listing of and run:
with Python 2.7:
$ python -m SimpleHTTPServer
with Python 3.x:
$ python -m http.server
This will start local simple HTTP server on port 8000.
Visit http://localhost:8000 and you will see listing of the current directory, which is even browsable.
Warning: Using this solution can be a security risk, as all the files are accessible for whoever visits published url.
Related
hi i am trying to deploy my python app on windows2012 server with iis .
i follow the process of add application in website on specific folder than changing handler mapping settings in adding handler script putting python path in it.
when i am trying to open it code show me text of app.py instead of running it.
only difference when i tried is that in his python code he started with
#!iusr
and i started directly have my python code.
source where i tried
https://www.youtube.com/watch?v=7whncKjSXK0
anyone have any clue
thanks for help
First, create python site for example mine is hello.py and place it under C:\pythonsite folder:
print('Content-Type: text/plain')
print('')
print('Hello, world!')
now open iis manager.
add a new site. select your python site folder and add bindings.
now click on the handler mapping from the middle pane.
in the handler mapping window select "add script map" from the action pane.
- add below details:
request path: *.py
executable: C:\Python37-32\python.exe %s %s
name:python
"C:\Python37-32\" is your python folder.
click request restrictions and make sure that the checkbox is unchecked.
when you click on ok it will open a prompt click "yes".
Note: make sure directory browsing is enabled and your python and site folder has iis_iusrs and iusr permission assigned with full control. you install iis CGI feature.
browse the site.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 12 months ago.
Improve this question
I want to access files in my local machine by using urls. For example "file:///usr/local/home/thapaliya/constants.py". What would be the best way to achieve this?
Use simple HTTP server:
python -m http.server 8000
Or for Python 2:
python -m SimpleHTTPServer 8000
https://docs.python.org/3/library/http.server.html
I copied from orszacky's answer for the similar question:
A little http server locally.
For Windows, the easiest is to install http-server globally using node's package manager:
npm install -g http-server
Then simply run http-server in any of your project directories:
C:\my_project> http-server
You can also use Python in Windows, and follow the instruction below:
For Linux, since Python is usually available in most Linux distributions,
run python -m SimpleHTTPServer
in your project directory, and you can load your page on http://localhost:8000
In Python 3 the SimpleHTTPServer module has been merged into http.server, so the new command is
python3 -m http.server.
Had the same need and have been searching for something simple but more versatile than python's built-in HTTP server (which is meant for debugging only and can't do range requests, i.e. doesn't handle streaming video properly).
Ended up writing a simple Web UI wrapper for caddy2 which relies on caddy's ability to return directory listings as JSON so the entire logic is browser-side. The main intent is to support audio/video playing in one frame while browsing related HTML/PDF or text in another split frame (there is some simple mapping with regexes for matching multimedia files with the related text files).
https://github.com/glowinthedark/mediabro4caddy
The old and currently unmaintained version is using python's built-in HTTP server which was extended to support range requests.
keep the files in a some folder which you want to access from a localhost
In command prompt go to that location and type
python -m http.server 8080
now type localhost :8080 in browser you will able to access files in that folder
if u want to use some js files for paticular html files then
<script src="http://localhost:8080/main.js"</script>
make sure you run this program on another port
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:
I have a small test python cgi script, which i have uploaded to /home/username/pyscripts which is above the /home/username/domain.com
I need a link I can type in the URL bar, which will lead to the script being executed and the content displayed in the browser.
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!
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
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.
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
My question is: how can I install DJANGO on a shared hosting account?
My hosting supports PYTHON 2.4. After copying the files to the ftp server, what is the next step? On Django site it says you need to to this:
tar xzvf Django-1.3.tar.gz
cd Django-1.3
sudo python setup.py install
But I dont see any command shell on my plesk account admin page. Now, there is an option on my hosting provider that gives what they call "SSH chrooted shell access with a limited command set" for €60 euros more.
Do I need to get that shell access upgrade for Django/PYTHON development?
Thanks very much!
They probably wouldn't give you root access with your SSH access anyway. You can "install" a python library without root access by just copying it into the same directory as your application. Extract the contents of Django-1.3.tar.gz on your computer (not the shared server), find the folder inside named "django" and upload this to the ftp server in the folder containing your Django project.
You could use a "django ready" hoster (eg google apps)!
here's an collection of links
https://code.djangoproject.com/wiki/DjangoFriendlyWebHosts
I have been wondering the same thing. Thinking it would be easier to simply install Django on local machine (if you’re the only developer). For quick and easy setup, use Bitnami Django. If there are others working with you or you needed remote access, can open port to your local machine to make it accessible via the Internet (e.g. noip.com). If project is getting big, then it would be worth investing your time setting up or finding a proper host.
I have installed Python 2.7 for Windows, and downloaded Django-1.2.3. Now, I want to build my first website with them. How can I get to the first hello world page, in a browser? Can I use Apache/XAMPP to go to http://localhost ? What are the base principles to get a website working?
Thank you
Just read the excellent and thorough Django tutorial. Django comes with a built-in simple web-server that you can run your websites on. It's just a Python script you run, and then you go to a port on localhost (by default port 8000). It's really quite simple and well-explained in the tutorial.
Specifically, look at the section named "The development server" in the page I linked to.
Personally I found this basic web-server to be very useful for all stages of website development.
# django-admin.py startproject myone
# cd myone
# python manage.py runserver