Use the MultiValueDict’s get
method. This is also present on standard dicts and is a way to fetch a value while providing a default if it does not exist.
is_private = request.POST.get('is_private', False)
Generally,
my_var = dict.get(<key>, <default>)
More Related Contents:
- Cron and virtualenv
- Expire a view-cache in Django?
- No module named ‘polls.apps.PollsConfigdjango’; Django project tutorial 2
- SyntaxError inconsistency in Python?
- How to call function that takes an argument in a Django template?
- Can you give a Django app a verbose name for use throughout the admin?
- Python Django Global Variables
- Django : Table doesn’t exist
- django – convert a list back to a queryset [duplicate]
- How can I make silent exceptions louder in tkinter?
- How do I separate my models out in django?
- django best approach for creating multiple type users
- Using request.user with Django ModelForm
- How to execute arithmetic operations between Model fields in django
- gunicorn autoreload on source change
- What is the best approach to change primary keys in an existing Django app?
- Order of Serializer Validation in Django REST Framework
- hasattr() vs try-except block to deal with non-existent attributes
- Difference between AbstractUser and AbstractBaseUser in Django?
- How to expire Django session in 5minutes?
- Django Admin – Disable the ‘Add’ action for a specific model
- How to re-raise an exception in nested try/except blocks?
- Django equivalent of PHP’s form value array/associative array
- How to add custom field in ModelSerializer?
- Run manage.py from AWS EB Linux instance
- How to perform filtering with a Django JSONField?
- “{% extends %}” vs “{% include %}” in Django Templates
- XlsxWriter object save as http response to create download in Django
- Multiple lookup_fields for django rest framework
- Apache mod_wsgi error: Forbidden You don’t have permission to access / on this server