简体   繁体   中英

How to render a django message after page refresh

Hi i am trying to show a message but the django message is not showing. The way i want to access this is if i send a webhook to a function in python for example. ill send a webhook post request using postman, and i will receive the message邮递员然后它正在工作

But if i then go to my page it is not showing这是当我转到运行应用程序的浏览器时

so my question is why is it working when i am using postman and not when using the browser, i also have a option to send the webhook request using a form on the app itself and ive added a refresh method as well but still nothing happpens.

is there a way to get a message on django if the python function is triggered with a webhook?

i am currently using 2 methods, both are working when using postman but neither works on the app itself

method 1

messages.add_message(request, messages.INFO, 'LONG was placed.')
    {% if messages %}
{% for message in messages %}
<div class = "alert alert-{{message.tags}}">{{message}}</div>
{% endfor %}
{% endif %}

and method 2

        storage = messages.get_messages(request)
        for message in storage:
            a=(message)
            print(a)
        storage.used = False
        context = {'a':a}
        return render(request,'crodlUSDT/syntax.html',context)
and then just calling it in my base.html {{a}}

i am new to coding in general but ive been struggling for days now so would appreciate any help, thanks

use this method for views.py:

messages.info(request, "Your message")

after in HTML files:

{% if messages %}
    {% for message in messages %}
        <div class = "alert alert-{{message.tags}}">{{message}}</div>
    {% endfor %}
{% endif %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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