简体   繁体   中英

How to embed HTML in SuccessMessageMixin?

How do I embed html code here. I tried using mark_safe, it didn't work

class PostCreateView(SuccessMessageMixin, LoginRequiredMixin, CreateView):
    model = Post
    form_class = PostForm
    template_name = 'blogApp/create.html'
    success_url = '/'
    success_message = mark_safe(
        '<strong>%(title)s</strong> Created Successfully')

Thank you in advance

You can try this:

success_message = "<h1>hello</h1>"

Now in your html, where you are rendering messages

put a safe filter like this:

{{message|safe}}

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