doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
UploadedFile.content_type The content-type header uploaded with the file (e.g. text/plain or application/pdf). Like any data supplied by the user, you shouldn’t trust that the uploaded file is actually this type. You’ll still need to validate that the file contains the content that the content-type header claims – “trust but verify.”
django.ref.files.uploads#django.core.files.uploadedfile.UploadedFile.content_type
UploadedFile.content_type_extra A dictionary containing extra parameters passed to the content-type header. This is typically provided by services, such as Google App Engine, that intercept and handle file uploads on your behalf. As a result your handler may not receive the uploaded file content, but instead a URL or other pointer to the file (see RFC 2388).
django.ref.files.uploads#django.core.files.uploadedfile.UploadedFile.content_type_extra
UploadedFile.multiple_chunks(chunk_size=None) Returns True if the uploaded file is big enough to require reading in multiple chunks. By default this will be any file larger than 2.5 megabytes, but that’s configurable; see below.
django.ref.files.uploads#django.core.files.uploadedfile.UploadedFile.multiple_chunks
UploadedFile.name The name of the uploaded file (e.g. my_file.txt).
django.ref.files.uploads#django.core.files.uploadedfile.UploadedFile.name
UploadedFile.read() Read the entire uploaded data from the file. Be careful with this method: if the uploaded file is huge it can overwhelm your system if you try to read it into memory. You’ll probably want to use chunks() instead; see below.
django.ref.files.uploads#django.core.files.uploadedfile.UploadedFile.read
UploadedFile.size The size, in bytes, of the uploaded file.
django.ref.files.uploads#django.core.files.uploadedfile.UploadedFile.size
class FileUploadHandler
django.ref.files.uploads#django.core.files.uploadhandler.FileUploadHandler
FileUploadHandler.chunk_size Size, in bytes, of the “chunks” Django should store into memory and feed into the handler. That is, this attribute controls the size of chunks fed into FileUploadHandler.receive_data_chunk. For maximum performance the chunk sizes should be divisible by 4 and should not exceed 2 GB (231 bytes) in size. When there are multiple chunk sizes provided by multiple handlers, Django will use the smallest chunk size defined by any handler. The default is 64*210 bytes, or 64 KB.
django.ref.files.uploads#django.core.files.uploadhandler.FileUploadHandler.chunk_size
FileUploadHandler.file_complete(file_size) Called when a file has finished uploading. The handler should return an UploadedFile object that will be stored in request.FILES. Handlers may also return None to indicate that the UploadedFile object should come from subsequent upload handlers.
django.ref.files.uploads#django.core.files.uploadhandler.FileUploadHandler.file_complete
FileUploadHandler.handle_raw_input(input_data, META, content_length, boundary, encoding) Allows the handler to completely override the parsing of the raw HTTP input. input_data is a file-like object that supports read()-ing. META is the same object as request.META. content_length is the length of the data in input_data. Don’t read more than content_length bytes from input_data. boundary is the MIME boundary for this request. encoding is the encoding of the request. Return None if you want upload handling to continue, or a tuple of (POST, FILES) if you want to return the new data structures suitable for the request directly.
django.ref.files.uploads#django.core.files.uploadhandler.FileUploadHandler.handle_raw_input
FileUploadHandler.new_file(field_name, file_name, content_type, content_length, charset, content_type_extra) Callback signaling that a new file upload is starting. This is called before any data has been fed to any upload handlers. field_name is a string name of the file <input> field. file_name is the filename provided by the browser. content_type is the MIME type provided by the browser – E.g. 'image/jpeg'. content_length is the length of the image given by the browser. Sometimes this won’t be provided and will be None. charset is the character set (i.e. utf8) given by the browser. Like content_length, this sometimes won’t be provided. content_type_extra is extra information about the file from the content-type header. See UploadedFile.content_type_extra. This method may raise a StopFutureHandlers exception to prevent future handlers from handling this file.
django.ref.files.uploads#django.core.files.uploadhandler.FileUploadHandler.new_file
FileUploadHandler.receive_data_chunk(raw_data, start) Receives a “chunk” of data from the file upload. raw_data is a bytestring containing the uploaded data. start is the position in the file where this raw_data chunk begins. The data you return will get fed into the subsequent upload handlers’ receive_data_chunk methods. In this way, one handler can be a “filter” for other handlers. Return None from receive_data_chunk to short-circuit remaining upload handlers from getting this chunk. This is useful if you’re storing the uploaded data yourself and don’t want future handlers to store a copy of the data. If you raise a StopUpload or a SkipFile exception, the upload will abort or the file will be completely skipped.
django.ref.files.uploads#django.core.files.uploadhandler.FileUploadHandler.receive_data_chunk
FileUploadHandler.upload_complete() Callback signaling that the entire upload (all files) has completed.
django.ref.files.uploads#django.core.files.uploadhandler.FileUploadHandler.upload_complete
FileUploadHandler.upload_interrupted() New in Django 3.2. Callback signaling that the upload was interrupted, e.g. when the user closed their browser during file upload.
django.ref.files.uploads#django.core.files.uploadhandler.FileUploadHandler.upload_interrupted
class MemoryFileUploadHandler
django.ref.files.uploads#django.core.files.uploadhandler.MemoryFileUploadHandler
class TemporaryFileUploadHandler
django.ref.files.uploads#django.core.files.uploadhandler.TemporaryFileUploadHandler
class backends.smtp.EmailBackend(host=None, port=None, username=None, password=None, use_tls=None, fail_silently=False, use_ssl=None, timeout=None, ssl_keyfile=None, ssl_certfile=None, **kwargs) This is the default backend. Email will be sent through a SMTP server. The value for each argument is retrieved from the matching setting if the argument is None: host: EMAIL_HOST port: EMAIL_PORT username: EMAIL_HOST_USER password: EMAIL_HOST_PASSWORD use_tls: EMAIL_USE_TLS use_ssl: EMAIL_USE_SSL timeout: EMAIL_TIMEOUT ssl_keyfile: EMAIL_SSL_KEYFILE ssl_certfile: EMAIL_SSL_CERTFILE The SMTP backend is the default configuration inherited by Django. If you want to specify it explicitly, put the following in your settings: EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' If unspecified, the default timeout will be the one provided by socket.getdefaulttimeout(), which defaults to None (no timeout).
django.topics.email#django.core.mail.backends.smtp.EmailBackend
django.core.mail.outbox
django.topics.testing.tools#django.core.mail.django.core.mail.outbox
class EmailMessage
django.topics.email#django.core.mail.EmailMessage
get_connection(backend=None, fail_silently=False, *args, **kwargs)
django.topics.email#django.core.mail.get_connection
mail_admins(subject, message, fail_silently=False, connection=None, html_message=None)
django.topics.email#django.core.mail.mail_admins
mail_managers(subject, message, fail_silently=False, connection=None, html_message=None)
django.topics.email#django.core.mail.mail_managers
send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, connection=None, html_message=None)
django.topics.email#django.core.mail.send_mail
send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None, connection=None)
django.topics.email#django.core.mail.send_mass_mail
class AppCommand
django.howto.custom-management-commands#django.core.management.AppCommand
AppCommand.handle_app_config(app_config, **options) Perform the command’s actions for app_config, which will be an AppConfig instance corresponding to an application label given on the command line.
django.howto.custom-management-commands#django.core.management.AppCommand.handle_app_config
class BaseCommand
django.howto.custom-management-commands#django.core.management.BaseCommand
BaseCommand.add_arguments(parser) Entry point to add parser arguments to handle command line arguments passed to the command. Custom commands should override this method to add both positional and optional arguments accepted by the command. Calling super() is not needed when directly subclassing BaseCommand.
django.howto.custom-management-commands#django.core.management.BaseCommand.add_arguments
BaseCommand.check(app_configs=None, tags=None, display_num_errors=False) Uses the system check framework to inspect the entire Django project for potential problems. Serious problems are raised as a CommandError; warnings are output to stderr; minor notifications are output to stdout. If app_configs and tags are both None, all system checks are performed. tags can be a list of check tags, like compatibility or models.
django.howto.custom-management-commands#django.core.management.BaseCommand.check
BaseCommand.create_parser(prog_name, subcommand, **kwargs) Returns a CommandParser instance, which is an ArgumentParser subclass with a few customizations for Django. You can customize the instance by overriding this method and calling super() with kwargs of ArgumentParser parameters.
django.howto.custom-management-commands#django.core.management.BaseCommand.create_parser
BaseCommand.execute(*args, **options) Tries to execute this command, performing system checks if needed (as controlled by the requires_system_checks attribute). If the command raises a CommandError, it’s intercepted and printed to stderr.
django.howto.custom-management-commands#django.core.management.BaseCommand.execute
BaseCommand.get_version() Returns the Django version, which should be correct for all built-in Django commands. User-supplied commands can override this method to return their own version.
django.howto.custom-management-commands#django.core.management.BaseCommand.get_version
BaseCommand.handle(*args, **options) The actual logic of the command. Subclasses must implement this method. It may return a string which will be printed to stdout (wrapped by BEGIN; and COMMIT; if output_transaction is True).
django.howto.custom-management-commands#django.core.management.BaseCommand.handle
BaseCommand.help A short description of the command, which will be printed in the help message when the user runs the command python manage.py help <command>.
django.howto.custom-management-commands#django.core.management.BaseCommand.help
BaseCommand.missing_args_message If your command defines mandatory positional arguments, you can customize the message error returned in the case of missing arguments. The default is output by argparse (“too few arguments”).
django.howto.custom-management-commands#django.core.management.BaseCommand.missing_args_message
BaseCommand.output_transaction A boolean indicating whether the command outputs SQL statements; if True, the output will automatically be wrapped with BEGIN; and COMMIT;. Default value is False.
django.howto.custom-management-commands#django.core.management.BaseCommand.output_transaction
BaseCommand.requires_migrations_checks A boolean; if True, the command prints a warning if the set of migrations on disk don’t match the migrations in the database. A warning doesn’t prevent the command from executing. Default value is False.
django.howto.custom-management-commands#django.core.management.BaseCommand.requires_migrations_checks
BaseCommand.requires_system_checks A list or tuple of tags, e.g. [Tags.staticfiles, Tags.models]. System checks registered in the chosen tags will be checked for errors prior to executing the command. The value '__all__' can be used to specify that all system checks should be performed. Default value is '__all__'. Changed in Django 3.2: In older versions, the requires_system_checks attribute expects a boolean value instead of a list or tuple of tags.
django.howto.custom-management-commands#django.core.management.BaseCommand.requires_system_checks
BaseCommand.style An instance attribute that helps create colored output when writing to stdout or stderr. For example: self.stdout.write(self.style.SUCCESS('...')) See Syntax coloring to learn how to modify the color palette and to see the available styles (use uppercased versions of the “roles” described in that section). If you pass the --no-color option when running your command, all self.style() calls will return the original string uncolored.
django.howto.custom-management-commands#django.core.management.BaseCommand.style
BaseCommand.suppressed_base_arguments New in Django 4.0. The default command options to suppress in the help output. This should be a set of option names (e.g. '--verbosity'). The default values for the suppressed options are still passed.
django.howto.custom-management-commands#django.core.management.BaseCommand.suppressed_base_arguments
django.core.management.call_command(name, *args, **options)
django.ref.django-admin#django.core.management.call_command
class LabelCommand
django.howto.custom-management-commands#django.core.management.LabelCommand
LabelCommand.handle_label(label, **options) Perform the command’s actions for label, which will be the string as given on the command line.
django.howto.custom-management-commands#django.core.management.LabelCommand.handle_label
LabelCommand.label A string describing the arbitrary arguments passed to the command. The string is used in the usage text and error messages of the command. Defaults to 'label'.
django.howto.custom-management-commands#django.core.management.LabelCommand.label
class Page(object_list, number, paginator) A page acts like a sequence of Page.object_list when using len() or iterating it directly.
django.ref.paginator#django.core.paginator.Page
Page.end_index() Returns the 1-based index of the last object on the page, relative to all of the objects in the paginator’s list. For example, when paginating a list of 5 objects with 2 objects per page, the second page’s end_index() would return 4.
django.ref.paginator#django.core.paginator.Page.end_index
Page.has_next() Returns True if there’s a next page.
django.ref.paginator#django.core.paginator.Page.has_next
Page.has_other_pages() Returns True if there’s a next or previous page.
django.ref.paginator#django.core.paginator.Page.has_other_pages
Page.has_previous() Returns True if there’s a previous page.
django.ref.paginator#django.core.paginator.Page.has_previous
Page.next_page_number() Returns the next page number. Raises InvalidPage if next page doesn’t exist.
django.ref.paginator#django.core.paginator.Page.next_page_number
Page.number The 1-based page number for this page.
django.ref.paginator#django.core.paginator.Page.number
Page.object_list The list of objects on this page.
django.ref.paginator#django.core.paginator.Page.object_list
Page.paginator The associated Paginator object.
django.ref.paginator#django.core.paginator.Page.paginator
Page.previous_page_number() Returns the previous page number. Raises InvalidPage if previous page doesn’t exist.
django.ref.paginator#django.core.paginator.Page.previous_page_number
Page.start_index() Returns the 1-based index of the first object on the page, relative to all of the objects in the paginator’s list. For example, when paginating a list of 5 objects with 2 objects per page, the second page’s start_index() would return 3.
django.ref.paginator#django.core.paginator.Page.start_index
class Paginator(object_list, per_page, orphans=0, allow_empty_first_page=True) A paginator acts like a sequence of Page when using len() or iterating it directly.
django.ref.paginator#django.core.paginator.Paginator
Paginator.allow_empty_first_page Optional. Whether or not the first page is allowed to be empty. If False and object_list is empty, then an EmptyPage error will be raised.
django.ref.paginator#django.core.paginator.Paginator.allow_empty_first_page
Paginator.count The total number of objects, across all pages. Note When determining the number of objects contained in object_list, Paginator will first try calling object_list.count(). If object_list has no count() method, then Paginator will fall back to using len(object_list). This allows objects, such as QuerySet, to use a more efficient count() method when available.
django.ref.paginator#django.core.paginator.Paginator.count
Paginator.ELLIPSIS New in Django 3.2. A translatable string used as a substitute for elided page numbers in the page range returned by get_elided_page_range(). Default is '…'.
django.ref.paginator#django.core.paginator.Paginator.ELLIPSIS
Paginator.get_elided_page_range(number, *, on_each_side=3, on_ends=2) New in Django 3.2. Returns a 1-based list of page numbers similar to Paginator.page_range, but may add an ellipsis to either or both sides of the current page number when Paginator.num_pages is large. The number of pages to include on each side of the current page number is determined by the on_each_side argument which defaults to 3. The number of pages to include at the beginning and end of page range is determined by the on_ends argument which defaults to 2. For example, with the default values for on_each_side and on_ends, if the current page is 10 and there are 50 pages, the page range will be [1, 2, '…', 7, 8, 9, 10, 11, 12, 13, '…', 49, 50]. This will result in pages 7, 8, and 9 to the left of and 11, 12, and 13 to the right of the current page as well as pages 1 and 2 at the start and 49 and 50 at the end. Raises InvalidPage if the given page number doesn’t exist.
django.ref.paginator#django.core.paginator.Paginator.get_elided_page_range
Paginator.get_page(number) Returns a Page object with the given 1-based index, while also handling out of range and invalid page numbers. If the page isn’t a number, it returns the first page. If the page number is negative or greater than the number of pages, it returns the last page. Raises an EmptyPage exception only if you specify Paginator(..., allow_empty_first_page=False) and the object_list is empty.
django.ref.paginator#django.core.paginator.Paginator.get_page
Paginator.num_pages The total number of pages.
django.ref.paginator#django.core.paginator.Paginator.num_pages
Paginator.object_list Required. A list, tuple, QuerySet, or other sliceable object with a count() or __len__() method. For consistent pagination, QuerySets should be ordered, e.g. with an order_by() clause or with a default ordering on the model. Performance issues paginating large QuerySets If you’re using a QuerySet with a very large number of items, requesting high page numbers might be slow on some databases, because the resulting LIMIT/OFFSET query needs to count the number of OFFSET records which takes longer as the page number gets higher.
django.ref.paginator#django.core.paginator.Paginator.object_list
Paginator.orphans Optional. Use this when you don’t want to have a last page with very few items. If the last page would normally have a number of items less than or equal to orphans, then those items will be added to the previous page (which becomes the last page) instead of leaving the items on a page by themselves. For example, with 23 items, per_page=10, and orphans=3, there will be two pages; the first page with 10 items and the second (and last) page with 13 items. orphans defaults to zero, which means pages are never combined and the last page may have one item.
django.ref.paginator#django.core.paginator.Paginator.orphans
Paginator.page(number) Returns a Page object with the given 1-based index. Raises PageNotAnInteger if the number cannot be converted to an integer by calling int(). Raises EmptyPage if the given page number doesn’t exist.
django.ref.paginator#django.core.paginator.Paginator.page
Paginator.page_range A 1-based range iterator of page numbers, e.g. yielding [1, 2, 3, 4].
django.ref.paginator#django.core.paginator.Paginator.page_range
Paginator.per_page Required. The maximum number of items to include on a page, not including orphans (see the orphans optional argument below).
django.ref.paginator#django.core.paginator.Paginator.per_page
django.core.serializers.get_serializer(format)
django.topics.serialization#django.core.serializers.get_serializer
class django.core.serializers.json.DjangoJSONEncoder
django.topics.serialization#django.core.serializers.json.DjangoJSONEncoder
django.core.signals.got_request_exception
django.ref.signals#django.core.signals.got_request_exception
django.core.signals.request_finished
django.ref.signals#django.core.signals.request_finished
django.core.signals.request_started
django.ref.signals#django.core.signals.request_started
dumps(obj, key=None, salt='django.core.signing', serializer=JSONSerializer, compress=False) Returns URL-safe, signed base64 compressed JSON string. Serialized object is signed using TimestampSigner.
django.topics.signing#django.core.signing.dumps
loads(string, key=None, salt='django.core.signing', serializer=JSONSerializer, max_age=None) Reverse of dumps(), raises BadSignature if signature fails. Checks max_age (in seconds) if given.
django.topics.signing#django.core.signing.loads
class Signer(key=None, sep=':', salt=None, algorithm=None) Returns a signer which uses key to generate signatures and sep to separate values. sep cannot be in the URL safe base64 alphabet. This alphabet contains alphanumeric characters, hyphens, and underscores. algorithm must be an algorithm supported by hashlib, it defaults to 'sha256'.
django.topics.signing#django.core.signing.Signer
class TimestampSigner(key=None, sep=':', salt=None, algorithm='sha256') sign(value) Sign value and append current timestamp to it. unsign(value, max_age=None) Checks if value was signed less than max_age seconds ago, otherwise raises SignatureExpired. The max_age parameter can accept an integer or a datetime.timedelta object. sign_object(obj, serializer=JSONSerializer, compress=False) New in Django 3.2. Encode, optionally compress, append current timestamp, and sign complex data structure (e.g. list, tuple, or dictionary). unsign_object(signed_obj, serializer=JSONSerializer, max_age=None) New in Django 3.2. Checks if signed_obj was signed less than max_age seconds ago, otherwise raises SignatureExpired. The max_age parameter can accept an integer or a datetime.timedelta object.
django.topics.signing#django.core.signing.TimestampSigner
sign(value) Sign value and append current timestamp to it.
django.topics.signing#django.core.signing.TimestampSigner.sign
sign_object(obj, serializer=JSONSerializer, compress=False) New in Django 3.2. Encode, optionally compress, append current timestamp, and sign complex data structure (e.g. list, tuple, or dictionary).
django.topics.signing#django.core.signing.TimestampSigner.sign_object
unsign(value, max_age=None) Checks if value was signed less than max_age seconds ago, otherwise raises SignatureExpired. The max_age parameter can accept an integer or a datetime.timedelta object.
django.topics.signing#django.core.signing.TimestampSigner.unsign
unsign_object(signed_obj, serializer=JSONSerializer, max_age=None) New in Django 3.2. Checks if signed_obj was signed less than max_age seconds ago, otherwise raises SignatureExpired. The max_age parameter can accept an integer or a datetime.timedelta object.
django.topics.signing#django.core.signing.TimestampSigner.unsign_object
class DecimalValidator(max_digits, decimal_places) Raises ValidationError with the following codes: 'max_digits' if the number of digits is larger than max_digits. 'max_decimal_places' if the number of decimals is larger than decimal_places. 'max_whole_digits' if the number of whole digits is larger than the difference between max_digits and decimal_places.
django.ref.validators#django.core.validators.DecimalValidator
class EmailValidator(message=None, code=None, allowlist=None) Parameters: message – If not None, overrides message. code – If not None, overrides code. allowlist – If not None, overrides allowlist. message The error message used by ValidationError if validation fails. Defaults to "Enter a valid email address". code The error code used by ValidationError if validation fails. Defaults to "invalid". allowlist Allowlist of email domains. By default, a regular expression (the domain_regex attribute) is used to validate whatever appears after the @ sign. However, if that string appears in the allowlist, this validation is bypassed. If not provided, the default allowlist is ['localhost']. Other domains that don’t contain a dot won’t pass validation, so you’d need to add them to the allowlist as necessary. Deprecated since version 3.2: The whitelist parameter is deprecated. Use allowlist instead. The undocumented domain_whitelist attribute is deprecated. Use domain_allowlist instead.
django.ref.validators#django.core.validators.EmailValidator
allowlist Allowlist of email domains. By default, a regular expression (the domain_regex attribute) is used to validate whatever appears after the @ sign. However, if that string appears in the allowlist, this validation is bypassed. If not provided, the default allowlist is ['localhost']. Other domains that don’t contain a dot won’t pass validation, so you’d need to add them to the allowlist as necessary.
django.ref.validators#django.core.validators.EmailValidator.allowlist
code The error code used by ValidationError if validation fails. Defaults to "invalid".
django.ref.validators#django.core.validators.EmailValidator.code
message The error message used by ValidationError if validation fails. Defaults to "Enter a valid email address".
django.ref.validators#django.core.validators.EmailValidator.message
class FileExtensionValidator(allowed_extensions, message, code) Raises a ValidationError with a code of 'invalid_extension' if the extension of value.name (value is a File) isn’t found in allowed_extensions. The extension is compared case-insensitively with allowed_extensions. Warning Don’t rely on validation of the file extension to determine a file’s type. Files can be renamed to have any extension no matter what data they contain.
django.ref.validators#django.core.validators.FileExtensionValidator
int_list_validator(sep=', ', message=None, code='invalid', allow_negative=False) Returns a RegexValidator instance that ensures a string consists of integers separated by sep. It allows negative integers when allow_negative is True.
django.ref.validators#django.core.validators.int_list_validator
class MaxLengthValidator(limit_value, message=None) Raises a ValidationError with a code of 'max_length' if the length of value is greater than limit_value, which may be a callable.
django.ref.validators#django.core.validators.MaxLengthValidator
class MaxValueValidator(limit_value, message=None) Raises a ValidationError with a code of 'max_value' if value is greater than limit_value, which may be a callable.
django.ref.validators#django.core.validators.MaxValueValidator
class MinLengthValidator(limit_value, message=None) Raises a ValidationError with a code of 'min_length' if the length of value is less than limit_value, which may be a callable.
django.ref.validators#django.core.validators.MinLengthValidator
class MinValueValidator(limit_value, message=None) Raises a ValidationError with a code of 'min_value' if value is less than limit_value, which may be a callable.
django.ref.validators#django.core.validators.MinValueValidator
class ProhibitNullCharactersValidator(message=None, code=None) Raises a ValidationError if str(value) contains one or more nulls characters ('\x00'). Parameters: message – If not None, overrides message. code – If not None, overrides code. message The error message used by ValidationError if validation fails. Defaults to "Null characters are not allowed.". code The error code used by ValidationError if validation fails. Defaults to "null_characters_not_allowed".
django.ref.validators#django.core.validators.ProhibitNullCharactersValidator
code The error code used by ValidationError if validation fails. Defaults to "null_characters_not_allowed".
django.ref.validators#django.core.validators.ProhibitNullCharactersValidator.code
message The error message used by ValidationError if validation fails. Defaults to "Null characters are not allowed.".
django.ref.validators#django.core.validators.ProhibitNullCharactersValidator.message
class RegexValidator(regex=None, message=None, code=None, inverse_match=None, flags=0) Parameters: regex – If not None, overrides regex. Can be a regular expression string or a pre-compiled regular expression. message – If not None, overrides message. code – If not None, overrides code. inverse_match – If not None, overrides inverse_match. flags – If not None, overrides flags. In that case, regex must be a regular expression string, or TypeError is raised. A RegexValidator searches the provided value for a given regular expression with re.search(). By default, raises a ValidationError with message and code if a match is not found. Its behavior can be inverted by setting inverse_match to True, in which case the ValidationError is raised when a match is found. regex The regular expression pattern to search for within the provided value, using re.search(). This may be a string or a pre-compiled regular expression created with re.compile(). Defaults to the empty string, which will be found in every possible value. message The error message used by ValidationError if validation fails. Defaults to "Enter a valid value". code The error code used by ValidationError if validation fails. Defaults to "invalid". inverse_match The match mode for regex. Defaults to False. flags The regex flags used when compiling the regular expression string regex. If regex is a pre-compiled regular expression, and flags is overridden, TypeError is raised. Defaults to 0.
django.ref.validators#django.core.validators.RegexValidator
code The error code used by ValidationError if validation fails. Defaults to "invalid".
django.ref.validators#django.core.validators.RegexValidator.code
flags The regex flags used when compiling the regular expression string regex. If regex is a pre-compiled regular expression, and flags is overridden, TypeError is raised. Defaults to 0.
django.ref.validators#django.core.validators.RegexValidator.flags
inverse_match The match mode for regex. Defaults to False.
django.ref.validators#django.core.validators.RegexValidator.inverse_match
message The error message used by ValidationError if validation fails. Defaults to "Enter a valid value".
django.ref.validators#django.core.validators.RegexValidator.message
regex The regular expression pattern to search for within the provided value, using re.search(). This may be a string or a pre-compiled regular expression created with re.compile(). Defaults to the empty string, which will be found in every possible value.
django.ref.validators#django.core.validators.RegexValidator.regex