Javascript 使用js从django应用程序调用脚本在google sheets中保存表单数据

Javascript 使用js从django应用程序调用脚本在google sheets中保存表单数据,javascript,django,django-forms,Javascript,Django,Django Forms,我正在制作一个web应用程序,其中有一个表单。我想将个人输入的数据存储在谷歌表单中映射的表单中。脚本成功地将数据保存到工作表中,但保存后,我将用户重定向到新页面。问题是当我附加数据映射代码时,重定向不起作用,但是如果我在调用脚本的地方注释代码,重定向就开始起作用 # here is the code where i have made the form in HTML file using crispyforms <form method="POST" id="

我正在制作一个web应用程序,其中有一个表单。我想将个人输入的数据存储在谷歌表单中映射的表单中。脚本成功地将数据保存到工作表中,但保存后,我将用户重定向到新页面。问题是当我附加数据映射代码时,重定向不起作用,但是如果我在调用脚本的地方注释代码,重定向就开始起作用

# here is the code where i have made the form in HTML file using crispyforms
<form method="POST" id="submit_info" class="bg-light p-4 p-md-5 contact-form" name="google-sheet">
          {% csrf_token %}
          {{form|crispy}}

          <div class="form-group text-center">
              <input type="submit"  value="Send Message" class="btn btn-primary center py-3 px-5">
          </div>
</form>

脚本中的
e.preventDefault()
基本上阻止了您调用POSTrequest@LinhNguyen非常感谢你的回答。那么,我们可以在这里做些什么呢。我的意思是这里有替代品吗?也许这能帮你
<script>
          const scriptURL = 'https://script.google.com/macros/s/AKfycbwN9jxAQwA9f7qF_tvUbpuRpIhObeAJT8nAqwIRrDZYMPqbyf6j/exec'
          const form = document.forms['google-sheet']
          form.addEventListener('submit', e => {
          e.preventDefault()
          fetch(scriptURL, { method: 'POST', body: new FormData(form)})})

</script>
def store(request):
if request.method == "POST":
    form = ContactForm(request.POST)
    if form.is_valid():
        form.save()
        return redirect('thankYouPage') # a second webpage where user should be redirected
else:
    form = ContactForm()
return render(request, 'home/index.html', {'form': form})