我想重写django ImageField的上载行为,以便在上传到某个url之后,该文件将被添加到ipfs节点。在
例如,我的模型类似于:
class Profile(models.Model):
picture = models.ImageField(upload_to=upload_location, blank=True)
我首先尝试像保存其他图像一样保存它,但是我给它一个IPFS散列,这将允许用户加载数据客户端。在
在我看来,我有以下代码来运行ipfs守护进程的实例。在
^{pr2}$但是,当我尝试运行python manage.py makemigrations
或runserver
时,守护进程会运行,但命令的其余部分不会运行
Initializing daemon...
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/174.56.29.92/tcp/4001
Swarm listening on /ip4/192.168.1.109/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready
如何启动ipfs守护进程和django服务器?看起来他们在监听同一个端口(django8000,ipfs8080),那么为什么我会遇到这个问题?在
https://pydigger.com/pypi/django-ipfs-storage
安装
。。代码::bash
配置
默认情况下,
ipfs_storage
向IPFS守护进程添加和固定内容 在本地主机上运行并返回指向公共 https://ipfs.io/ipfs/HTTP网关要自定义此项,请在
settings.py
中设置以下变量:IPFS_STORAGE_API_URL
:默认为'http://localhost:5001/api/v0/'
。在IPFS_GATEWAY_API_URL
:默认为'https://ipfs.io/ipfs/'
。在将
IPFS_GATEWAY_API_URL
设置为'http://localhost:8080/ipfs/'
为 通过本地守护进程的HTTP网关提供内容。在使用
有两种方法可以使用Django存储后端。在
作为默认后端 ~~~~~~~~~~~~~~~~~~~
将IPFS用作
Django’s default file storage backend <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-DEFAULT_FILE_STORAGE>
\uuU:。。代码::python
^{pr2}$对于特定的FileField ~~~~~~~~~~~~~~~~~~~~~~~~~~
或者,您可能只想将IPFS存储后端用于 单个字段:
。。代码::python
相关问题 更多 >
编程相关推荐