【问题标题】:Anybody see the problem? #Bootoast script有人看到问题了吗? #Bootast 脚本
【发布时间】:2021-05-04 19:54:12
【问题描述】:

尝试让 Bootoast 在我的网站上运行,我尝试在其中传递消息。你可以看到下面的代码。前端使用 Django-bootstrap。

BASE.HTML

   <script srs="https://unpkg.com/bootoast@1.0.1/dist/bootoast.min.js"></script>
  <link rel="stylesheet" href="https://unpkg.com/bootoast@1.0.1/dist/bootoast.min.css">

  <script>
    function toast(message, type) {
      bootoast.toast({
        position: 'bottom-center',
        message,
        type,
      });
    }

    {% if messages %}

    {% for message in messages %}
    toast('{{ message }}', '{{ message.tags }}')
    {% endfor %}

    {% endif %}
  </script>

VIEWS.PY

@login_required(login_url="/sign-in/?next=/customer/")
def profile_page(request):
   user_form = forms.BasicUserForm(instance=request.user)
   customer_form = forms.BasicCustomerForm(instance=request.user.customer)

   if request.method == "POST":
       user_form = forms.BasicUserForm(request.POST, instance=request.user)
       customer_form = forms.BasicCustomerForm(request.POST, request.FILES, instance=request.user.customer)

       if user_form.is_valid() and customer_form.is_valid():
           user_form.save()
           customer_form.save()

           messages.success(request, 'Your profile has been updated')
           return redirect(reverse('customer:profile'))


   return render(request, 'customer/profile.html', {
       "user_form": user_form,
       "customer_form": customer_form
   })

所以我得到的错误是:

(index):197 Uncaught ReferenceError: bootoast is not defined

我是盲人还是没有定义?

【问题讨论】:

  • 您能分享一下您遇到的错误吗?
  • 这就是问题所在。我没有收到错误;它只是不会显示,而不是网站。
  • 你能在浏览器的调试器控制台中看到什么吗?
  • 我得到这个错误:(index):124 Uncaught ReferenceError: bootoast is not defined at toast ((index):124) at (index):134 toast @ (index):124

标签: javascript python django bootstrap-4 reference


【解决方案1】:
<script srs="https://unpkg.com/bootoast@1.0.1/dist/bootoast.min.js"></script>

应该是

<script src="https://unpkg.com/bootoast@1.0.1/dist/bootoast.min.js"></script>

【讨论】:

    猜你喜欢
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 2020-11-17
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    相关资源
    最近更新 更多