60👍
✅
Your server should never produce a 500 error page.
You can avoid the error by using:
my_param = request.GET.get('param', default_value)
or:
my_param = request.GET.get('param')
if my_param is None:
return HttpResponseBadRequest()
12👍
Yes, you should check for KeyError
in that case. Or you could do this:
if 'param' in request.GET:
my_param = request.GET['param']
else:
my_param = default_value
- [Django]-How to make an auto-filled and auto-incrementing field in django admin
- [Django]-Why does DEBUG=False setting make my django Static Files Access fail?
- [Django]-What is the difference between cached_property in Django vs. Python's functools?
1👍
How about passing default value if param doesn’t exist ?
my_param = request.GET.get('param', 'defaultvalue')
- [Django]-How to stop gunicorn properly
- [Django]-How to automate createsuperuser on django?
- [Django]-Docker/Kubernetes + Gunicorn/Celery – Multiple Workers vs Replicas?
Source:stackexchange.com