当有人在 django 中订阅时,如何删除弹出的时事通讯

how to remove a newletter popup when someone sucscribes in django

当有人订阅时事通讯时,我想自动删除刚刚订阅的用户的弹出窗口,我尝试创建一个 subscribed = False,然后在用户订阅时将其更改为 subscribed = True。但它不起作用。我可以很容易地实现这一点,因为用户已登录,但在这种情况下,即使未经身份验证的用户也可以订阅时事通讯,所以这就是问题所在。

views.py

subscribed = False
    if request.method == "POST":
        form = NewsLetterForm(request.POST)
        if form.is_valid:
            form.save()
            messages.success(request, f"Subscription Successfull, Thank you!! - Now check your mail")
            subscribed = True
            return redirect('/')
    else:
        form = NewsLetterForm()

templates.html

{% if subscribed != True %}
<p class="mb-0">Subscribe to our <b>NewsLetter</b></p>
<form class="form-inline" method="POST">
   {% csrf_token %}
   {{form.email}}
   <button type="submit" class="btn btn-success-soft btn-sm" type="submit">Get Now</button>
{% endif %}

Django Close Bootstrap Modal On Submit

这解决了我的问题,我必须做的就是在用户提交表单时关闭它