最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】CentOS服务器中搭建Python的Flask的REST API

CentOS crifan 3110浏览 0评论

很久之前就在别的服务器上搭建过Flask服务器。

现在要在一台CentOS中搭建Flask服务器。

搭建Flask服务器之前,先去找虚拟环境。

之前知道有个virtual env,貌似还算好用,但是也是有点点麻烦的说。

前不久听说有个更好的,用于虚拟环境的,去找找。

【已解决】Python3中选择合适的虚拟环境工具

然后就是去:

【已解决】Mac本地用pipenv搭建Flask开发环境

通过:

查看python已安装模块的方法小结 – CSDN博客

去用:

<code>[root@naturling-general-01 ~]# pydoc modules

Please wait a moment while I gather a list of all available modules...

BaseHTTPServer      bz2                 itertools           schedutils
Bastion             cPickle             jinja2              select
CDROM               cProfile            json                selinux
CGIHTTPServer       cStringIO           jsonpatch           sets
Cheetah             calendar            jsonpointer         setuptools
ConfigParser        certifi             keyword             sgmllib
Cookie              cgi                 lib2to3             sha
DLFCN               cgitb               liblzma             shelve
DocXMLRPCServer     chardet             linecache           shlex
HTMLParser          chunk               linuxaudiodev       shutil
IN                  cloudinit           locale              signal
MimeWriter          cmath               logging             site
Queue               cmd                 lzma                slip
SimpleHTTPServer    code                macpath             smtpd
SimpleXMLRPCServer  codecs              macurl2path         smtplib
SocketServer        codeop              mailbox             snack
StringIO            collections         mailcap             sndhdr
TYPES               colorsys            markdown            socket
UserDict            commands            markupbase          spwd
UserList            compileall          markupsafe          sqlite3
UserString          compiler            marshal             sqlitecachec
_LWPCookieJar       configobj           math                sre
_MozillaCookieJar   contextlib          md5                 sre_compile
__builtin__         cookielib           mhlib               sre_constants
__future__          copy                mimetools           sre_parse
_abcoll             copy_reg            mimetypes           ssl
_ast                crypt               mimify              stat
_bisect             csv                 mmap                statvfs
_bsddb              ctypes              modulefinder        string
_codecs             curl                multifile           stringold
_codecs_cn          curses              multiprocessing     stringprep
_codecs_hk          datetime            mutex               strop
_codecs_iso2022     dbhash              netrc               struct
_codecs_jp          dbm                 new                 subprocess
_codecs_kr          dbus                nis                 sunau
_codecs_tw          decimal             nntplib             sunaudio
_collections        decorator           ntpath              symbol
_crypt              difflib             nturl2path          symtable
_csv                dircache            numbers             sys
_ctypes             dis                 oauth               sysconfig
_curses             distutils           opcode              syslog
_curses_panel       dl                  operator            tabnanny
_dbus_bindings      doctest             optparse            tarfile
_dbus_glib_bindings dumbdbm             os                  telnetlib
_elementtree        dummy_thread        os2emxpath          tempfile
_functools          dummy_threading     ossaudiodev         termios
_hashlib            easy_install        parser              test
_heapq              email               pdb                 textwrap
_hotshot            encodings           perf                this
_io                 errno               pickle              thread
_json               exceptions          pickletools         threading
_locale             fcntl               pip                 time
_lsprof             filecmp             pipes               timeit
_multibytecodec     fileinput           pkg_resources       timing
_multiprocessing    firewall            pkgutil             toaiff
_osx_support        fnmatch             platform            token
_pyio               formatter           plistlib            tokenize
_random             fpformat            popen2              trace
_snack              fractions           poplib              traceback
_socket             ftplib              posix               tty
_sqlite3            functools           posixfile           tuned
_sqlitecache        future_builtins     posixpath           types
_sre                gc                  pprint              unicodedata
_ssl                gdbm                prettytable         unittest
_strptime           genericpath         procfs              urlgrabber
_struct             getopt              profile             urllib
_symtable           getpass             pstats              urllib2
_sysconfigdata      gettext             pty                 urllib3
_threading_local    gi                  pwd                 urlparse
_warnings           glob                py_compile          user
_weakref            gpgme               pyclbr              uu
_weakrefset         grp                 pycurl              uuid
abc                 gzip                pydoc               validate
acutil              hashlib             pydoc_data          warnings
aifc                heapq               pyexpat             wave
antigravity         hmac                pygtkcompat         weakref
anydbm              hotshot             pyudev              webbrowser
argparse            htmlentitydefs      quopri              whichdb
array               htmllib             random              wsgiref
ast                 httplib             re                  xattr
asynchat            idlelib             readline            xdrlib
asyncore            idna                repr                xml
atexit              ihooks              requests            xmllib
audiodev            imageop             resource            xmlrpclib
audioop             imaplib             rexec               xxsubtype
backports           imghdr              rfc822              yaml
base64              imp                 rlcompleter         yum
bdb                 importlib           robotparser         zipfile
binascii            imputil             rpm                 zipimport
binhex              iniparse            rpmUtils            zlib
bisect              inspect             runpy               
bsddb               io                  sched               

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".

[root@naturling-general-01 ~]# 
</code>

知道了,远端服务器中,并没有安装pipenv。

然后接着去开发Flask的内部接口:

【已解决】Flask中实现rest的api去返回典型格式的json数据

然后接着再去:

【已解决】Flask中获取REST API接口的传递进来的参数

再去搞清楚如何添加log:

【已解决】Flask中添加log且输出到文件中

然后再去尝试连接远程的MongoDB,去读取需要的数据:

【已解决】Flask中连接远程MongoDB数据库的gridfs并返回查询到的文件数据

接着再去想办法,把得到的mongo中girdfs的文件数据,想办法生成绝对的url路径:

【已解决】Flask中Mongo的GridFS数据如何保存为绝对路径的下载文件地址

然后就先去:

【已解决】把Python3的pipenv的Flask部署到CentOS服务器上

转载请注明:在路上 » 【已解决】CentOS服务器中搭建Python的Flask的REST API

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.163 seconds, using 22.19MB memory