Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 views
in Technique[技术] by (71.8m points)

python 3.x - How to display "permission_denied_message" in custom 403.html page in Django

How do we correctly display exception message in custom 403 error in Django?

In my signup view I am using:

class SignUpView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
    login_url = 'error_403'
    # ....
    # ...
    permission_denied_message = 'You are not allowed this transaction!! Ha Ha!!'
#    raise PermissionDenied() # ('permission_denied_message')
    raise_exception = True

Now how do I display the message ("permission_denied_message"?) in my custom 403.html?

This is my function to render the error page:

def error_403(request, exception):
    data = {}
    add_user = 'add_user'
    data = {'perm': add_user}
    return render(request, '403.html', data)

I have been through a lot of matter on the subject (including those on SO) but could not succeed in displaying the error message (except the static message that I have put in my "403.html"). I have used {{ exception}} in the template but nothing gets displayed (execpt the static message that I already have).

1. How do I display the permission_denied_message in custom 403 page?

2. Presently I am manually updating some raw data in dict data{} in function error_403, which gets rendered on the 403 error page. What is the correct usage of the dict?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...