Topic guide Testing tools The test client
```python >>> c = Client() >>> c.get("/", SCRIPT_NAME="/app/") ``` If you already have the GET arguments in URL-encoded form, you can use that encoding instead of using the data argument.
669 sections in Django 5.1 Search all versions →
Topic guide Testing tools The test client
```python >>> c = Client() >>> c.get("/", SCRIPT_NAME="/app/") ``` If you already have the GET arguments in URL-encoded form, you can use that encoding instead of using the data argument.
… django.conf.urls) - has_add_permission() (InlineModelAdmin method) - (ModelAdmin method) - has_change_permission() (InlineModelAdmin method) - (ModelAdmin method) - has_changed() (Field method) - (Form method) - has_delete_permission() (InlineModelAdmin method) - (ModelAdmin method) - has_error() (Form method) - has_header() (HttpResponse method) - has_key() (backends.base.SessionBase …
… (BoundField attribute) - (Field attribute) - (LabelCommand attribute) - (Options attribute) - label_lower (Options attribute) - label_suffix (Field attribute) - (Form attribute) - label_tag() (BoundField method) - LabelCommand (class in django.core.management) - Lag (class in django.db.models.functions) - language - template …
How-to
… can use csrf_protect() on particular views you want to protect (see below). 2. In any template that uses a POST form, use the csrf_token tag inside the <form> element if the form is for an internal URL, e.g.: This should …
How-to How to use Django’s CSRF protection
It must be used both on views that insert the CSRF token in the output, and on those that accept the POST form data. (These are often the same view function, but not always).
How-to How to use Django’s CSRF protection
By default, a ‘403 Forbidden’ response is sent to the user if an incoming request fails the checks performed by CsrfViewMiddleware.
How-to How to create custom model fields Writing a field subclass
Writing a custom field can be a tricky process, particularly if you’re doing complex conversions between your Python types and your database and serialization formats.
How-to How to create custom template tags and filters Writing custom template tags
When you call render() on a compiled template object, the template calls render() on each Node in its node list, with the given context. The results are all concatenated together to form the output of the template.
How-to How to configure and use logging
… with the records they receive filters, to provide additional control over the transfer of records, and even modify records in-place formatters, to convert LogRecord objects to a string or other form for consumption by human beings or another system There …
Internals Contributing to Django
Join it, to become familiar with what we’re doing and how we talk about it. You’ll be able to form relationships with more experienced contributors who are there to help guide you towards success.
Internals Triaging tickets Other triage attributes
Keyword search finds the keyword string anywhere in the keywords. For example, clicking on a ticket with the keyword “form” will yield similar tickets tagged with keywords containing strings such as “formset”, “modelformset”, and “ManagementForm”.
Internals Django Deprecation Timeline
The undocumented function django.contrib.formtools.utils.security_hash will be removed, instead use django.contrib.formtools.utils.form_hmac The function-based generic view modules will be removed in favor of their class-based equivalents, outlined here. The django.core.servers.basehttp.AdminMediaHandler will be removed. In its place use django.contrib.staticfiles.handlers.StaticFilesHandler.
Internals Django’s security policies Reporting security issuesReporting guidelines
… sanitized: Developers must always validate and sanitize input before using it. The correct approach would be to use a Django form to ensure email is properly validated: Similarly, as Django’s raw SQL constructs (such as extra() and RawSQL expression) provide …
Tutorial Writing your first Django app, part 2 Introducing the Django Admin
There’s the “What’s up?” question we created earlier: Click the “What’s up?” question to edit it: Things to note here: The form is automatically generated from the Question model.
Tutorial Writing your first Django app, part 3
Question “detail” page – displays a question text, with no results but with a form to vote. Question “results” page – displays results for a particular question. Vote action – handles voting for a particular choice in a particular question.
Tutorial Writing your first Django app, part 7
The “Add choice” form looks like this: In that form, the “Question” field is a select box containing every question in the database. Django knows that a ForeignKey should be represented in the admin as a <select> box.
Reference Applications
app_name is the full name of the app, e.g. 'django.contrib.admin'. apps.get_model(app_label,model_name,require_ready=True) : Returns the Model with the given app_label and model_name. As a shortcut, this method also accepts a single argument in the form app_label.model_name. model_name is case-insensitive.
Reference Class-based generic views - flattened index Editing views
classCreateView Attributes (with optional accessor): content_type context_object_name [get_context_object_name()] extra_context fields form_class [get_form_class()] http_method_names initial [get_initial()] model pk_url_kwarg prefix [get_prefix()] query_pk_and_slug queryset [get_queryset()] response_class [render_to_response()] slug_field [get_slug_field()] slug_url_kwarg success_url [get_success_url()] template_engine template_name [get_template_names()] template_name_field template_name_suffix Methods as_view() dispatch() form_invalid() form_valid() get() …
Reference Class-based generic views - flattened index Editing views
classUpdateView Attributes (with optional accessor): content_type context_object_name [get_context_object_name()] extra_context fields form_class [get_form_class()] http_method_names initial [get_initial()] model pk_url_kwarg prefix [get_prefix()] query_pk_and_slug queryset [get_queryset()] response_class [render_to_response()] slug_field [get_slug_field()] slug_url_kwarg success_url [get_success_url()] template_engine template_name [get_template_names()] template_name_field template_name_suffix Methods as_view() dispatch() form_invalid() form_valid() get() …
Reference
The following views are described on this page and provide a foundation for editing content: django.views.generic.edit.FormView django.views.generic.edit.CreateView django.views.generic.edit.UpdateView django.views.generic.edit.DeleteView NOTE: The messages framework contains > SuccessMessageMixin, which > facilitates presenting messages about successful form submissions.