50👍
✅
Try:
def show_toolbar(request):
return not request.is_ajax() and request.user and request.user.username == "yourusername"
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'projectname.settings.show_toolbar',
# Rest of config
}
11👍
The accepted answer is no longer correct. Newer versions of the toolbar need the value of the SHOW_TOOLBAR_CALLBACK
key to be a string with the full import path of the function. So if you’re defining your callback function your settings.py
file, you’d have to add:
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'projectname.settings.show_toolbar',
}
- [Django]-How to dynamically provide lookup field name in Django query?
- [Django]-Is there a simple way to get group names of a user in django
- [Django]-How to get the name of current app within a template?
2👍
If you face No .rsplit() Error
. NEW SOLUTION:
Because SHOW_TOOLBAR_CALLBACK
is now a dotted string path and not support a callable.
edit your settings.py
:
def custom_show_toolbar(request):
return True # Always show toolbar, for example purposes only.
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'your_project_name.settings.custom_show_toolbar',
}
- [Django]-How to seed Django project ? – insert a bunch of data into the project for initialization
- [Django]-Adding a APIView to Django REST Framework Browsable API
- [Django]-Can't connect to local MySQL server through socket '/tmp/mysql.sock
0👍
In Django 4+ this username validation worked for me:
def show_toolbar(request):
return str(request.user) == "username" #... any other validations
- [Django]-How do I perform a batch insert in Django?
- [Django]-Access tuple in django template
- [Django]-How can I set two primary key fields for my models in Django?
Source:stackexchange.com