2

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?

277roshan
  • 316
  • 2
  • 12

3 Answers3

1

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

Mikko Ohtamaa
  • 69,174
  • 40
  • 208
  • 346
0

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.
Cloud Cho
  • 933
  • 11
  • 16
0

1.keep the files in a some folder which you want to access from a localhost

2.In command prompt go to that location and type python -m http.server 8080

3.now type localhost :8080 in browser you will able to access files in that folder

  1. if u want to use some js files for paticular html files then "<script src="http://localhost:8080/main.js"" make sure you run this programm on another port