如何使用Django保存到远程服务器 [英] How to save to a remote server with Django

查看:268
本文介绍了如何使用Django保存到远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚接触Python和Django。我最近有一个Django应用程序,它在Linux Mint 18.3中的localhost上具有Postgresql数据库。

I'm fairly new to Python and Django. I've recently got a Django app working on localhost in Linux Mint 18.3 with a Postgresql database.

我已将应用程序上载到PythonAnywhere,但是不幸的是,某些NLP功能(斯坦福POS)需要Java。有没有办法解析和处理本地系统上的数据并将其保存到远程Postgres DB并从远程服务器提供数据?

I've uploaded the app to PythonAnywhere, but unfortunately it requires Java for some of the NLP features (Stanford POS). Is there a way to parse and process the data on a local system and save it to the remote Postgres DB and serving the data from the remote server?

关于SSH隧道的一些答案,但是我不确定这是否适用于这里?或者,是否可以保存到本地数据库并定期将数据迁移到远程数据库?

I've looked at some answers on here regarding SSH tunnelling, but I'm not sure this applies here? Alternatively would it be possible to save to the local database and periodically migrate the data to the remote database?

推荐答案

是-从本地计算机访问PythonAnywhere Postgres DB,则需要使用SSH隧道。如果您在本地计算机上使用类似Unix的操作系统(例如Linux或Mac),请在此帮助页面将进行一些调整。

Yes -- to access your PythonAnywhere Postgres DB from your local machine, you'll need to use SSH tunnelling. If you're using a Unix-like operating system (eg. Linux or Mac) on your local machine, the "Manual SSH tunnelling" instructions at the bottom of this help page will handle that, with a couple of tweaks.

帮助页面上的SSH命令为:

The SSH command on the help page is:

ssh -L 3306:username.mysql.pythonanywhere-services.com:3306 username@ssh.pythonanywhere.com

如您所见,它适用于MySQL。为了使其适用于您的PythonAnywhere Postgres服务器,请替换:

...which, as you can see, is for MySQL. To make it work for your PythonAnywhere Postgres server, replace:


  • 第一个 3306 使用 5432 (这意味着在您的本地计算机上,它将使用默认的Postgres端口)

  • username.mysql.pythonanywhere-services.com 和PythonAnywhere内数据库页面上 Postgres选项卡上的Postgres服务器主机名。

  • 第二个 3306 ,其端口来自PythonAnywhere内数据库页面上 Postgres选项卡。

  • The first 3306 with 5432 (which means that on your local machine, it will use the default Postgres port)
  • The username.mysql.pythonanywhere-services.com with the Postgres server hostname from the "Postgres" tab on the "Databases" page inside PythonAnywhere.
  • The second 3306 with the port from the "Postgres" tab on the "Databases" page inside PythonAnywhere.

所以您最终会得到类似的东西

So you'll wind up with something like

ssh -L 5432:username-123.postgres.pythonanywhere-services.com:10123 username@ssh.pythonanywhere.com

...对于<$具有不同的值c $ c>用户名, 123 10123

运行该命令(并输入您的PythonAnywhere登录密码,它将提示您输入密码),在看起来像Postgres服务器的所有本地进程的机器上进行装饰,但实际上只是将所有内容来回转发到PythonAnywhere托管的数据库服务器。因此,您可以在本地运行解析和处理代码,它将透明地工作。

When you run that command (and entered your PythonAnywhere login password, which it will prompt you for), a process will start up on your machine that looks like a Postgres server to all local processes, but is actually just forwarding everything back and forth to the PythonAnywhere-hosted database server. So you can run your parsing and processing code locally, and it will work transparently.

这篇关于如何使用Django保存到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆