user2307087
user2307087

Reputation: 423

Pass a variable in an error message in Django

I am trying to pass a variable to a url in an error message. How can I implement this?

In views.py

        error_messages = {
        'inactivated': _('Please <a href="../send" click here to 
                          to receive an activation key.')
       }

I'd like to pass an email address to the send url when a user gets an inactivated error message and click the link.

enter image description here

Upvotes: 2

Views: 1533

Answers (2)

Toan Nguyen
Toan Nguyen

Reputation: 661

You could pass the variable as an URL:

In views.py

context_data = {'retry_url': reverse(viewname="send_activation_email", args=(), kwargs={})}
return render( request, template_name="template.html", context=context_data)

In template.html:

<p><a href="{{ retry_url }}">click here</a> to receive an activation key.</p>

Upvotes: 0

Deja Vu
Deja Vu

Reputation: 731

String formatting should work

foo = 'fooo'
bar = 'baar'
'%s %s' % (foo, bar)
>> 'fooo baar'

Upvotes: 3

Related Questions