简体   繁体   English

如何将本地存储的表单数据传递到Django视图并将其保存在数据库中

[英]how can I pass locally stored form data to django view and save it on the database

How can I pass form data from an offline website to django view which than will save it on the database. 我如何将表单数据从脱机网站传递到django视图,然后将其保存在数据库中。

Filled in form > save form > saves in local storage > when connected to internet > upload the data to database 填写表格>保存表格>保存在本地存储中>连接到互联网后>将数据上传到数据库

Is there a guide on how to do this or can someone help? 是否有关于如何执行此操作的指南,或者有人可以提供帮助?

First of all, you will need some api (like django-rest-framework to provide some way to comunicate from your local - offline website to global - online website. Using normal django views wouldn't be efficient for that. 首先,您将需要一些api(例如django-rest-framework),以提供某种方式从本地-离线网站到全球-在线网站进行通信。使用常规django视图并不是有效的方法。

Next - you need some way to check if connection can be estabilished - and run that check for example in 5 minute intervals (using cron propably, or some external process because django won't handle that by itself). 接下来-您需要某种方法来检查是否可以建立连接-并例如每隔5分钟运行一次该检查(适当地使用cron或某些外部过程,因为django不能自行处理)。 You can also trigger that check by hand. 您也可以手动触发该检查。

Next - when connection can be estabilished, you need to connect to API and push all changes from your local database to global website. 接下来-可以建立连接时,您需要连接到API并将所有更改从本地数据库推送到全球网站。 After each change, you should mark it in local database that it is already synchronized or just remove it from queue. 每次更改后,您都应该在本地数据库中将其标记为已同步,或者将其从队列中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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