-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstruction to make python server
More file actions
50 lines (29 loc) · 1.24 KB
/
Copy pathinstruction to make python server
File metadata and controls
50 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Open Command Prompt:
Press Win + R, type cmd, and press Enter to open the Command Prompt.
Navigate to the desired directory:
Use the cd command to navigate to the directory where you want to create your server files.
bash
cd path\to\your\directory
Create a Python file:
Create a new Python file (e.g., server.py) using a text editor like Notepad or a code editor like Visual Studio Code.
notepad server.py
Edit server.py:
Open the server.py file and add the following code to create a basic HTTP server.
python
import http.server
import socketserver
# Set the port number
PORT = 8000
# Create a simple handler to serve files
Handler = http.server.SimpleHTTPRequestHandler
# Create the server
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("Server started at port", PORT)
# Start the server
httpd.serve_forever()
Save and close the file.
Run the server:
Go back to the Command Prompt, and execute the following command to run your server:
python server.py
Access the server:
Open your web browser and go to http://localhost:8000. You should see a directory listing of the files in the directory where your server.py file is located.