简体   繁体   中英

How to deploy flask application to cgi-bin folder on shared hosting?

My freelance client is giving FTP access to the shared hosting, I am new to web development and can't figure out how to deploy the flask app to cgi-bin folder, please help me understand how this works?

.htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f # Don't interfere with static files
RewriteRule ^(.*)$ /public_html/app.cgi/$1 [L]


app.py  file

import sys, subprocess
# implement pip as a subprocess:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'flask'])

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return "Hello, world"


if __name__ == '__main__':
    app.run()


app.cgi  file

#!/usr/bin/python3
from wsgiref.handlers import CGIHandler
from app import app

CGIHandler().run(app)

First create a python script which will contain:

import sys
import subprocess

# implement pip as a subprocess:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 
'flask'])

And then follow the instructions given by Hostgator . Please mark it as an answer if it is helpful!

Rajdeep, a Full-Stack Python Developer

Sorry but the Flask hosting can't be done within Shared-Hosting.
You need DigitalOcean or Heroku or PythonAnywhere (easiest) Hosting to deploy a Flask / Django Website.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM