Python ssh后的主目录

Python ssh后的主目录,python,ssh,flask,web-deployment,Python,Ssh,Flask,Web Deployment,我正在我大学的一个服务器/集群上开发一个web应用程序,里面有我想要在后端运行的所有代码 我将首先发布我的一般性问题,然后是我得到的详细代码和错误消息。我的主要问题是,当我通常在我的计算机上本地开发任何使用python和微框架或框架(如flask或django)的web应用程序时,我在浏览器上访问的地址是:,以确保所有内容都在运行,或者是本地主机附近的某个地址。但是,当我通过ssh连接到服务器/集群时,我的新地址是什么?假设我去user@cluster1.uni.ece.edu. 我是否可以通过

我正在我大学的一个服务器/集群上开发一个web应用程序,里面有我想要在后端运行的所有代码

我将首先发布我的一般性问题,然后是我得到的详细代码和错误消息。我的主要问题是,当我通常在我的计算机上本地开发任何使用python和微框架或框架(如flask或django)的web应用程序时,我在浏览器上访问的地址是:,以确保所有内容都在运行,或者是本地主机附近的某个地址。但是,当我通过ssh连接到服务器/集群时,我的新地址是什么?假设我去user@cluster1.uni.ece.edu. 我是否可以通过访问查看我的网站的输出

详细规格:

我运行的代码应该允许任何人从客户端通过web浏览器将图像上传到服务器

import os

from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from werkzeug import secure_filename

# Initialize the Flask application

app = Flask(__name__)

# This will be th path to the upload directory
app.config['UPLOAD_FOLDER'] = 'uploads/'

# These are the extension that we are accepting to be uploaded
app.config['ALLOWED_EXTENSIONS'] = set(['png','jpg','jpeg'])

# For a given file, return whether it's an allowed type or not
def allowed_file(file_name):
  return '.' in filename and \
    filename.rsplit('.',1)[1] in app.config['ALLOWED_EXTENSIONS']

# This route will show a form to perform an AJAX request
# jQuery is loaded to execute the request and update the 
# value of the operation

@app.route('/')
def index():
  return render_template('index.html')

#Route that will process the file upload
@app.route('/upload',methods=['POST'])
def upload():
  #Get the name of the uploaded file
  file = request.files['file']
  #Check if the file is one of the allowed types/extensions
  if file and allowed_file(file.filename):
    #Make the filename safe, remove unsupported chars
    filename = secure_filename(file.filename)
    #Move the file from the temporal folder to
    #the upload folder we setup
    file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
    #Redirect the user to the uplaoded_file route, which
    #will basically show on the browser the uploaded file
    return redirect(url_for('uploaded_file',filename=filename))


# This route is expecting a parameter containing the name of a file.
# Then it will locate that file on the upload directory and show it on the
# browser, so if the user uploads an image, that image is going to be shown
# after the upload.

@app.route('/uploads/<filename>')
def uploaded_file(filename):
  return send_from_directory(app.config['UPLOAD_FOLDER'],filename)


if __name__ == '__main__':
  app.run(
    host='0.0.0.0',
    port=int("80"),
    debug=True
  )
上面的代码是从另一个教程网站上借用的。无论如何,我得到的错误是:

 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
Traceback (most recent call last):
  File "Demo1.py", line 60, in <module>
    debug=True
  File "/home/arturo/miniconda/envs/venv1/lib/python2.7/site-packages/flask/app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "/home/arturo/miniconda/envs/venv1/lib/python2.7/site-packages/werkzeug/serving.py", line 618, in run_simple
    test_socket.bind((hostname, port))
  File "/home/arturo/miniconda/envs/venv1/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied

我的一个朋友正在开发一个类似的网站,不知怎么的,他设法让它运行起来:

你第一个问题的答案是肯定的。如果在服务器上运行web应用程序,您将能够看到网站的输出。默认情况下,应用程序将在端口5000上运行

对于第二个问题,请检查以下问题的答案:。您已将开发服务器的端口更改为80,而不是根用户。按如下方式运行应用程序:

if __name__ == '__main__':
  app.run(
    host='0.0.0.0',
    debug=True
  )
您将能够在中看到输出。 如果你想在80端口上运行它,你必须有根访问权限。 如果您想部署它,我建议您使用像或这样的生产服务器