mteb/BrightProStackoverflowRetrieval huggingface dataset:
###  ` url  ` ¶

Returns an absolute path reference (a URL without the domain name) matching a
given view and optional parameters. Any special characters in the resulting
path will be encoded using [ ` iri_to_uri()  `
](../../utils/#django.utils.encoding.iri_to_uri
"django.utils.encoding.iri_to_uri") .

This is a way to output links without violating the DRY principle by having to
hard-code URLs in your templates:

    
    
    {% url 'some-url-name' v1 v2 %}
    

The first argument is a [ URL pattern name
](../../../topics/http/urls/#naming-url-patterns) . It can be a quoted literal
or any other context variable. Additional arguments are optional and should be
space-separated values that will be used as arguments in the URL. The example
above shows passing positional arguments. Alternatively you may use keyword
syntax:

    
    
    {% url 'some-url-name' arg1=v1 arg2=v2 %}
    

Do not mix both positional and keyword syntax in a single call. All arguments
required by the URLconf should be present.

For example, suppose you have a view, ` app_views.client  ` , whose URLconf
takes a client ID (here, ` client()  ` is a method inside the views file `
app_views.py  ` ). The URLconf line might look like this:

    
    
    path("client/<int:id>/", app_views.client, name="app-views-client")
    

If this app’s URLconf is included into the project’s URLconf under a path such
as this:

    
    
    path("clients/", include("project_name.app_name.urls"))
    

…then, in a template, you can create a link to this view like this:

    
    
    {% url 'app-views-client' client.id %}
    

The template tag will output the string ` /clients/client/123/  ` .

Note that if the URL you’re reversing doesn’t exist, you’ll get an [ `
NoReverseMatch  ` ](../../exceptions/#django.urls.NoReverseMatch
"django.urls.NoReverseMatch") exception raised, which will cause your site to
display an error page.

If you’d like to retrieve a URL without displaying it, you can use a slightly
different call:

    
    
    {% url 'some-url-name' arg arg2 as the_url %}
    
    <a href="{{ the_url }}">I'm linking to {{ the_url }}</a>
    

The scope of the variable created by the ` as  var  ` syntax is the ` {%
block  %}  ` in which the ` {%  url  %}  ` tag appears.

This ` {%  url  ...  as  var  %}  ` syntax will _not_ cause an error if the
view is missing. In practice you’ll use this to link to views that are
optional:

    
    
    {% url 'some-url-name' as the_url %}
    {% if the_url %}
      <a href="{{ the_url }}">Link to optional stuff</a>
    {% endif %}
    

If you’d like to retrieve a namespaced URL, specify the fully qualified name:

    
    
    {% url 'myapp:view-name' %}
    

This will follow the normal [ namespaced URL resolution strategy
](../../../topics/http/urls/#topics-http-reversing-url-namespaces) , including
using any hints provided by the context as to the current application.

Warning

Don’t forget to put quotes around the URL pattern ` name  ` , otherwise the
value will be interpreted as a context variable!
###  ` truncatechars_html  ` ¶

Similar to  ` truncatechars  ` , except that it is aware of HTML tags. Any
tags that are opened in the string and not closed before the truncation point
are closed immediately after the truncation.

For example:

    
    
    {{ value|truncatechars_html:7 }}
    

If ` value  ` is ` "<p>Joel  is  a  slug</p>"  ` , the output will be `
"<p>Joel  i…</p>"  ` .

Newlines in the HTML content will be preserved.

Size of input string

Processing large, potentially malformed HTML strings can be resource-intensive
and impact service performance. ` truncatechars_html  ` limits input to the
first five million characters.

Changed in Django 3.2.22:

In older versions, strings over five million characters were processed.
###  ` linebreaks  ` ¶

Replaces line breaks in plain text with appropriate HTML; a single newline
becomes an HTML line break ( ` <br> ` ) and a new line followed by a blank
line becomes a paragraph break ( ` </p> ` ).

For example:

    
    
    {{ value|linebreaks }}
    

If ` value  ` is ` Joel\nis  a  slug  ` , the output will be ` <p>Joel<br>is
a  slug</p> ` .
###  ` resetcycle  ` ¶

Resets a previous  cycle  so that it restarts from its first item at its next
encounter. Without arguments, ` {%  resetcycle  %}  ` will reset the last ` {%
cycle  %}  ` defined in the template.

Example usage:

    
    
    {% for coach in coach_list %}
        <h1>{{ coach.name }}</h1>
        {% for athlete in coach.athlete_set.all %}
            <p class="{% cycle 'odd' 'even' %}">{{ athlete.name }}</p>
        {% endfor %}
        {% resetcycle %}
    {% endfor %}
    

This example would return this HTML:

    
    
    <h1>Gareth</h1>
    <p class="odd">Harry</p>
    <p class="even">John</p>
    <p class="odd">Nick</p>
    
    <h1>John</h1>
    <p class="odd">Andrea</p>
    <p class="even">Melissa</p>
    

Notice how the first block ends with ` class="odd"  ` and the new one starts
with ` class="odd"  ` . Without the ` {%  resetcycle  %}  ` tag, the second
block would start with ` class="even"  ` .

You can also reset named cycle tags:

    
    
    {% for item in list %}
        <p class="{% cycle 'odd' 'even' as stripe %} {% cycle 'major' 'minor' 'minor' 'minor' 'minor' as tick %}">
            {{ item.data }}
        </p>
        {% ifchanged item.category %}
            <h1>{{ item.category }}</h1>
            {% if not forloop.first %}{% resetcycle tick %}{% endif %}
        {% endifchanged %}
    {% endfor %}
    

In this example, we have both the alternating odd/even rows and a “major” row
every fifth row. Only the five-row cycle is reset when a category changes.
###  ` truncatewords_html  ` ¶

Similar to  ` truncatewords  ` , except that it is aware of HTML tags. Any
tags that are opened in the string and not closed before the truncation point,
are closed immediately after the truncation.

This is less efficient than  ` truncatewords  ` , so should only be used when
it is being passed HTML text.

For example:

    
    
    {{ value|truncatewords_html:2 }}
    

If ` value  ` is ` "<p>Joel  is  a  slug</p>"  ` , the output will be `
"<p>Joel  is  …</p>"  ` .

Newlines in the HTML content will be preserved.

Size of input string

Processing large, potentially malformed HTML strings can be resource-intensive
and impact service performance. ` truncatewords_html  ` limits input to the
first five million characters.

Changed in Django 3.2.22:

In older versions, strings over five million characters were processed.
default. Hello {{ name }}
    
    {% autoescape off %}
        This will not be auto-escaped: {{ data }}.
    
        Nor this: {{ other_data }}
        {% autoescape on %}
            Auto-escaping applies again: {{ name }}
        {% endautoescape %}
    {% endautoescape %}
    

The auto-escaping tag passes its effect onto templates that extend the current
one as well as templates included via the [ ` include  ` ](../builtins/#std-
templatetag-include) tag, just like all block tags. For example:

` base.html  ` ¶

    
    
    {% autoescape off %}
    <h1>{% block title %}{% endblock %}</h1>
    {% block content %}
    {% endblock %}
    {% endautoescape %}
    

` child.html  ` ¶

    
    
    {% extends "base.html" %}
    {% block title %}This &amp; that{% endblock %}
    {% block content %}{{ greeting }}{% endblock %}
    

Because auto-escaping is turned off in the base template, it will also be
turned off in the child template, resulting in the following rendered HTML
when the ` greeting  ` variable contains the string ` <b>Hello!</b> ` :

    
    
    <h1>This &amp; that</h1>
    <b>Hello!</b>
    

###  Notes  ¶

Generally, template authors don’t need to worry about auto-escaping very much.
Developers on the Python side (people writing views and custom filters) need
to think about the cases in which data shouldn’t be escaped, and mark data
appropriately, so things Just Work in the template.

If you’re creating a template that might be used in situations where you’re
not sure whether auto-escaping is enabled, then add an [ ` escape  `
](../builtins/#std-templatefilter-escape) filter to any variable that needs
escaping. When auto-escaping is on, there’s no danger of the [ ` escape  `
](../builtins/#std-templatefilter-escape) filter _double-escaping_ data – the
[ ` escape  ` ](../builtins/#std-templatefilter-escape) filter does not affect
auto-escaped variables.

###  String literals and automatic escaping  ¶

As we mentioned earlier, filter arguments can be strings:

    
    
    {{ data|default:"This is a string literal." }}
    

All string literals are inserted **without** any automatic escaping into the
template – they act as if they were all passed through the [ ` safe  `
](../builtins/#std-templatefilter-safe) filter. The reasoning behind this is
that the template author is in control of what goes into the string literal,
so they can make sure the text is correctly escaped when the template is
written.

This means you would write :

    
    
    {{ data|default:"3 &lt; 2" }}
    

…rather than:

    
    
    {{ data|default:"3 < 2" }}  {# Bad! Don't do this. #}
    

This doesn’t affect what happens to data coming from the variable itself. The
variable’s contents are still automatically escaped, if necessary, because
they’re beyond the control of the template author.
###  ` spaceless  ` ¶

Removes whitespace between HTML tags. This includes tab characters and
newlines.

Example usage:

    
    
    {% spaceless %}
        <p>
            <a href="foo/">Foo</a>
        </p>
    {% endspaceless %}
    

This example would return this HTML:

    
    
    <p><a href="foo/">Foo</a></p>
    

Only space between _tags_ is removed – not space between tags and text. In
this example, the space around ` Hello  ` won’t be stripped:

    
    
    {% spaceless %}
        <strong>
            Hello
        </strong>
    {% endspaceless %}
* [ Twitter  ](https://twitter.com/treehouse "Twitter")
* [ YouTube  ](https://youtube.com/user/gotreehouse "YouTube")
* [ Facebook  ](https://facebook.com/teamtreehouse "Facebook")
* [ LinkedIn  ](https://linkedin.com/company/treehouse-island-inc- "LinkedIn")
* [ Instagram  ](https://instagram.com/teamtreehouse "Instagram")
* [ ](https://tiktok.com/@team.treehouse "TikTok")
* [ ](https://discord.com/invite/RNNxkTHAUT "Discord")
####  ` get_static_prefix  ` ¶

You should prefer the  ` static  ` template tag, but if you need more control
over exactly where and how [ ` STATIC_URL  ` ](../../settings/#std-setting-
STATIC_URL) is injected into the template, you can use the  `
get_static_prefix  ` template tag:

    
    
    {% load static %}
    <img src="{% get_static_prefix %}images/hi.jpg" alt="Hi!">
    

There’s also a second form you can use to avoid extra processing if you need
the value multiple times:

    
    
    {% load static %}
    {% get_static_prefix as STATIC_PREFIX %}
    
    <img src="{{ STATIC_PREFIX }}images/hi.jpg" alt="Hi!">
    <img src="{{ STATIC_PREFIX }}images/hi2.jpg" alt="Hello!">
###  ` urlize  ` ¶

Converts URLs and email addresses in text into clickable links.

This template tag works on links prefixed with ` http://  ` , ` https://  ` ,
or ` www.  ` . For example, ` https://goo.gl/aia1t  ` will get converted but `
goo.gl/aia1t  ` won’t.

It also supports domain-only links ending in one of the original top level
domains ( ` .com  ` , ` .edu  ` , ` .gov  ` , ` .int  ` , ` .mil  ` , ` .net
` , and ` .org  ` ). For example, ` djangoproject.com  ` gets converted.

Links can have trailing punctuation (periods, commas, close-parens) and
leading punctuation (opening parens), and ` urlize  ` will still do the right
thing.

Links generated by ` urlize  ` have a ` rel="nofollow"  ` attribute added to
them.

For example:

    
    
    {{ value|urlize }}
    

If ` value  ` is ` "Check  out  www.djangoproject.com"  ` , the output will be
` "Check  out  <a  href="http://www.djangoproject.com"
rel="nofollow">www.djangoproject.com</a>"  ` .

In addition to web links, ` urlize  ` also converts email addresses into `
mailto:  ` links. If ` value  ` is ` "Send  questions  to  foo@example.com"  `
, the output will be ` "Send  questions  to  <a
href="mailto:foo@example.com">foo@example.com</a>"  ` .

The ` urlize  ` filter also takes an optional parameter ` autoescape  ` . If `
autoescape  ` is ` True  ` , the link text and URLs will be escaped using
Django’s built-in  ` escape  ` filter. The default value for ` autoescape  `
is ` True  ` .

Note

If ` urlize  ` is applied to text that already contains HTML markup, or to
email addresses that contain single quotes ( ` '  ` ), things won’t work as
expected. Apply this filter only to plain text.
##  Templates  ¶

A template is a text file. It can generate any text-based format (HTML, XML,
CSV, etc.).

A template contains **variables** , which get replaced with values when the
template is evaluated, and **tags** , which control the logic of the template.

Below is a minimal template that illustrates a few basics. Each element will
be explained later in this document.

    
    
    {% extends "base_generic.html" %}
    
    {% block title %}{{ section.title }}{% endblock %}
    
    {% block content %}
    <h1>{{ section.title }}</h1>
    
    {% for story in story_list %}
    <h2>
      <a href="{{ story.get_absolute_url }}">
        {{ story.headline|upper }}
      </a>
    </h2>
    <p>{{ story.tease|truncatewords:"100" }}</p>
    {% endfor %}
    {% endblock %}
    

Philosophy

Why use a text-based template instead of an XML-based one (like Zope’s TAL)?
We wanted Django’s template language to be usable for more than just XML/HTML
templates. You can use the template language for any text-based format such as
emails, JavaScript and CSV.
* [ Code  ](/opencv/opencv)
* [ Issues  ](/opencv/opencv/issues)
* [ Pull requests  ](/opencv/opencv/pulls)
* [ Discussions  ](/opencv/opencv/discussions)
* [ Actions  ](/opencv/opencv/actions)
* [ Projects  ](/opencv/opencv/projects)
* [ Wiki  ](/opencv/opencv/wiki)
* [ Security  ](/opencv/opencv/security)
* [ Insights  ](/opencv/opencv/pulse)
[ Picamera ](index.html)

release-1.13

  * [ 1\. Installation ](install.html)
  * [ 2\. Getting Started ](quickstart.html)
  * [ 3\. Basic Recipes ](recipes1.html)
  * 4\. Advanced Recipes 
    * 4.1. Capturing to a numpy array 
    * 4.2. Capturing to an OpenCV object 
    * 4.3. Unencoded image capture (YUV format) 
    * 4.4. Unencoded image capture (RGB format) 
    * 4.5. Custom outputs 
    * 4.6. Unconventional file outputs 
    * 4.7. Rapid capture and processing 
    * 4.8. Unencoded video capture 
    * 4.9. Rapid capture and streaming 
    * 4.10. Web streaming 
    * 4.11. Capturing images whilst recording 
    * 4.12. Recording at multiple resolutions 
    * 4.13. Recording motion vector data 
    * 4.14. Splitting to/from a circular stream 
    * 4.15. Custom encoders 
    * 4.16. Raw Bayer data captures 
    * 4.17. Using a flash with the camera 
  * [ 5\. Frequently Asked Questions (FAQ) ](faq.html)
  * [ 6\. Camera Hardware ](fov.html)
  * [ 7\. Development ](development.html)
  * [ 8\. Deprecated Functionality ](deprecated.html)
  * [ 9\. API - The PiCamera Class ](api_camera.html)
  * [ 10\. API - Streams ](api_streams.html)
  * [ 11\. API - Renderers ](api_renderers.html)
  * [ 12\. API - Encoders ](api_encoders.html)
  * [ 13\. API - Exceptions ](api_exc.html)
  * [ 14\. API - Colors and Color Matching ](api_color.html)
  * [ 15\. API - Arrays ](api_array.html)
  * [ 16\. API - mmalobj ](api_mmalobj.html)
  * [ 17\. Change log ](changelog.html)
  * [ 18\. License ](license.html)

__ [ Picamera ](index.html)

  * [ Docs ](index.html) » 
  * 4\. Advanced Recipes 
  * [ Edit on GitHub ](https://github.com/waveform80/picamera/blob/release-1.13/docs/recipes2.rst)

* * *

#  4\. Advanced Recipes  ¶

The following recipes involve advanced techniques and may not be “beginner
friendly”. Please feel free to suggest enhancements or additional recipes.

Warning

When trying out these scripts do _not_ name your file ` picamera.py  ` .
Naming scripts after existing Python modules will cause errors when you try
and import those modules (because Python checks the current directory before
checking other paths).
* [ Code  ](/opencv/opencv)
* [ Issues  2.4k  ](/opencv/opencv/issues)
* [ Pull requests  142  ](/opencv/opencv/pulls)
* [ Discussions  ](/opencv/opencv/discussions)
* [ Actions  ](/opencv/opencv/actions)
* [ Projects  2  ](/opencv/opencv/projects)
* [ Wiki  ](/opencv/opencv/wiki)
* [ Security  ](/opencv/opencv/security)
* [ Insights  ](/opencv/opencv/pulse)
* [ Legal Information ](https://www.nvidia.com/en-us/about-nvidia/legal-info/)
* [ Terms of Use ](https://developer.nvidia.com/legal/terms)
* [ Privacy Policy ](https://www.nvidia.com/en-us/about-nvidia/privacy-policy/)
* [ Contact ](https://developer.nvidia.com/contact)
* [ Cookie Policy ](https://www.nvidia.com/en-us/about-nvidia/cookie-policy/ "NVIDIA websites use cookies to deliver and improve the website experience. See our cookie policy for further details on how we use cookies and how to change your cookie settings.")
##  3.16. Controlling the LED  ¶

In certain circumstances, you may find the V1 camera module’s red LED a
hindrance (the V2 camera module lacks an LED). For example, in the case of
automated close-up wild-life photography, the LED may scare off animals. It
can also cause unwanted reflected red glare with close-up subjects.

One trivial way to deal with this is simply to place some opaque covering on
the LED (e.g. blue-tack or electricians tape). Another method is to use the `
disable_camera_led  ` option in the [ boot configuration
](https://www.raspberrypi.org/documentation/configuration/config-txt.md) .

However, provided you have the [ RPi.GPIO
](https://pypi.python.org/pypi/RPi.GPIO) package installed, and provided your
Python process is running with sufficient privileges (typically this means
running as root with ` sudo  python  ` ), you can also control the LED via the
[ ` led  ` ](api_camera.html#picamera.PiCamera.led "picamera.PiCamera.led")
attribute:

    
    
    import picamera
    
    camera = picamera.PiCamera()
    # Turn the camera's LED off
    camera.led = False
    # Take a picture while the LED remains off
    camera.capture('foo.jpg')
    

Note

The camera LED cannot currently be controlled when the module is attached to a
Raspberry Pi 3 Model B as the GPIO that controls the LED has moved to a GPIO
expander not directly accessible to the ARM processor.

Warning

Be aware when you first use the LED property it will set the GPIO library to
Broadcom (BCM) mode with ` GPIO.setmode(GPIO.BCM)  ` and disable warnings with
` GPIO.setwarnings(False)  ` . The LED cannot be controlled when the library
is in BOARD mode.

[ Next  ](recipes2.html "4. Advanced Recipes") [ Previous ](quickstart.html
"2. Getting Started")

* * *

© Copyright 2013-2016 Dave Jones  Revision ` e18d7098 ` .

Built with [ Sphinx ](http://sphinx-doc.org/) using a [ theme
](https://github.com/rtfd/sphinx_rtd_theme) provided by [ Read the Docs
](https://readthedocs.org) .

Read the Docs  v: release-1.13

Versions

     [ latest ](/en/latest/)
     [ release-1.13 ](/en/release-1.13/)

Downloads

     [ pdf ](//readthedocs.org/projects/picamera/downloads/pdf/release-1.13/)
     [ htmlzip ](//readthedocs.org/projects/picamera/downloads/htmlzip/release-1.13/)
     [ epub ](//readthedocs.org/projects/picamera/downloads/epub/release-1.13/)

On Read the Docs

     [ Project Home ](//readthedocs.org/projects/picamera/?fromdocs=picamera)
     [ Builds ](//readthedocs.org/builds/picamera/?fromdocs=picamera)

* * *

Free document hosting provided by [ Read the Docs
](http://www.readthedocs.org) .
[ ![@reunanen](https://avatars.githubusercontent.com/u/2297572?s=52&v=4)
](/reunanen) [
![@scipioni](https://avatars.githubusercontent.com/u/3766283?s=52&v=4)
](/scipioni) [
![@w4w4n78](https://avatars.githubusercontent.com/u/4031903?s=52&v=4)
](/w4w4n78) [
![@alalek](https://avatars.githubusercontent.com/u/4981219?s=52&v=4)
](/alalek) [
![@phelix001](https://avatars.githubusercontent.com/u/5187100?s=52&v=4)
](/phelix001) [
![@chrjen](https://avatars.githubusercontent.com/u/10513014?s=52&v=4)
](/chrjen) [ ![@TVI-
BIZ](https://avatars.githubusercontent.com/u/19244057?s=52&v=4) ](/TVI-BIZ) [
![@n-gineer](https://avatars.githubusercontent.com/u/20650428?s=52&v=4)
](/n-gineer) [
![@hcgfighting](https://avatars.githubusercontent.com/u/21313968?s=52&v=4)
](/hcgfighting) [
![@anvinder](https://avatars.githubusercontent.com/u/22649426?s=52&v=4)
](/anvinder) [
![@Namburger](https://avatars.githubusercontent.com/u/25712149?s=52&v=4)
](/Namburger) [
![@cassidylinhares](https://avatars.githubusercontent.com/u/30815527?s=52&v=4)
](/cassidylinhares) [
![@zjdx1998](https://avatars.githubusercontent.com/u/35225920?s=52&v=4)
](/zjdx1998) [
![@kartikpodugu](https://avatars.githubusercontent.com/u/37222502?s=52&v=4)
](/kartikpodugu) [
![@BoShaoLi](https://avatars.githubusercontent.com/u/38877000?s=52&v=4)
](/BoShaoLi) [
![@jbasement](https://avatars.githubusercontent.com/u/40320614?s=52&v=4)
](/jbasement) [
![@IstiakFahim28](https://avatars.githubusercontent.com/u/54916519?s=52&v=4)
](/IstiakFahim28) [
![@arielkantorovich](https://avatars.githubusercontent.com/u/56262208?s=52&v=4)
](/arielkantorovich) [
![@duriantaco](https://avatars.githubusercontent.com/u/57052760?s=52&v=4)
](/duriantaco) [
![@liuzihaode](https://avatars.githubusercontent.com/u/64268662?s=52&v=4)
](/liuzihaode) and others
[ Picamera ](index.html)

release-1.13

  * [ 1\. Installation ](install.html)
  * [ 2\. Getting Started ](quickstart.html)
  * 3\. Basic Recipes 
    * 3.1. Capturing to a file 
    * 3.2. Capturing to a stream 
    * 3.3. Capturing to a PIL Image 
    * 3.4. Capturing resized images 
    * 3.5. Capturing consistent images 
    * 3.6. Capturing timelapse sequences 
    * 3.7. Capturing in low light 
    * 3.8. Capturing to a network stream 
    * 3.9. Recording video to a file 
    * 3.10. Recording video to a stream 
    * 3.11. Recording over multiple files 
    * 3.12. Recording to a circular stream 
    * 3.13. Recording to a network stream 
    * 3.14. Overlaying images on the preview 
    * 3.15. Overlaying text on the output 
    * 3.16. Controlling the LED 
  * [ 4\. Advanced Recipes ](recipes2.html)
  * [ 5\. Frequently Asked Questions (FAQ) ](faq.html)
  * [ 6\. Camera Hardware ](fov.html)
  * [ 7\. Development ](development.html)
  * [ 8\. Deprecated Functionality ](deprecated.html)
  * [ 9\. API - The PiCamera Class ](api_camera.html)
  * [ 10\. API - Streams ](api_streams.html)
  * [ 11\. API - Renderers ](api_renderers.html)
  * [ 12\. API - Encoders ](api_encoders.html)
  * [ 13\. API - Exceptions ](api_exc.html)
  * [ 14\. API - Colors and Color Matching ](api_color.html)
  * [ 15\. API - Arrays ](api_array.html)
  * [ 16\. API - mmalobj ](api_mmalobj.html)
  * [ 17\. Change log ](changelog.html)
  * [ 18\. License ](license.html)

__ [ Picamera ](index.html)

  * [ Docs ](index.html) » 
  * 3\. Basic Recipes 
  * [ Edit on GitHub ](https://github.com/waveform80/picamera/blob/release-1.13/docs/recipes1.rst)

* * *

#  3\. Basic Recipes  ¶

The following recipes should be reasonably accessible to Python programmers of
all skill levels. Please feel free to suggest enhancements or additional
recipes.

Warning

When trying out these scripts do _not_ name your file ` picamera.py  ` .
Naming scripts after existing Python modules will cause errors when you try
and import those modules (because Python checks the current directory before
checking other paths).