vercel Is a code hosting platform , It can host your static html Interface , Can even host your node.js And Python Server script , It's a blessing for lazy people who don't want to have servers !
To use vercel First you need a vercel account number , Here I am Recommend to use GitHub Account Association , So you can be in vercel Directly hosting your GitHub Items in the library , Realize the development and deployment in one step .
P.S: If the link is not available, please go online scientifically
stay Vercel The home page can be used directly GitHub Sign in
Click on new project
If you can't find the library you need , Click on the new jump interface Adjust Github App Permissions
Then you can import the project you need to host and successfully host it
trusteeship python A project is no different from hosting a static website , However, there are several points to be noted :
1. Use vercel trusteeship python project , First you need to create a project directory api
Folder , It holds your python Script .
2.api The folder is also marked with index.py
For the entrance , Of course you can be in Vercel Program entry specified in .
Yours python The script structure should look like the following example :
from http.server import BaseHTTPRequestHandler
class handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write("DearXuan's API by python!".encode())
return
When your hosting is successful , You can enter... In the address field ${your_project_name}.vercel.app/api
To view your backend interface ~
It doesn't seem very good to package all the packages into your program , But don't worry ,vercel I have considered the problem for you , You just need to generate a package that contains the package you referenced requirements.txt
That's all right. .
As for how to generate requirements.txt Well ? There are many ways , But many don't work . After my test , Find only one effective way :
pipreqs ./ --encoding=utf8
In this way, even if your project references an external package, it can run normally ~