I have Syntax Error When I edit django messages

210 views Asked by At

I want to edit django error mesages like class error mesages.But when I add if controller in HTML documents, I meet syntax error

Note: (just when I use if controller I have syntax error)

Views content;

 from django.contrib import messages


 if request.method=="POST":
       form = RegisterForm(request.POST)
       if form.is_valid():
           username = form.cleaned_data.get("username")
           password = form.cleaned_data.get("passowrd")
           newUser = User(username = username)
           newUser.set_password(password)
           newUser.save()
           login(request,newUser)
           messages.success(request,"Kayıt Başarılı")
           messages.warning(request,"DANGER")
           return redirect(index)
           
       context ={
            "form":form
        }
       return render(request,"register.html",context)

Note: I added 2 messages for try when I don't add if controller its working

Layout content;

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

Error output:

Could not parse the remainder: '=="warning"' from 'message.tags=="warning"' 
1

There are 1 answers

0
willeM_ Van Onsem On BEST ANSWER

You need to add some spacing:

{% if message.tags == "warning" %}
    …
{% endif %}