PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] How to embed HTML in SuccessMessageMixin?

 July 11, 2022     django, message, python     No comments   

Issue

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


Solution

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}}


Answered By - Nitin Raturi
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing