Skip to main content

Installation

  1. pip install django_render_partial

  2. Add 'django_render_partial' to INSTALLED_APPS

  3. Ensure that 'django.template.context_processors.request' is in TEMPLATES['OPTIONS']['context_processors']

Usage

Write a template for partial view, e.g. partial_view.html:

<p>{{ arg1 }} + {{ arg2 }} = {{ result }}</p>

Write a partial view:

def partial_view(request, *args, **kwargs):
    result = kwargs['arg1'] + kwargs['arg2']
    kwargs['result'] = result
    return render(request, 'partial_view.html', kwargs)

if you are using function-based views, or:

class PartialView(TemplateView):
    template_name = 'partial_view.html'

    def get_context_data(self, **kwargs):
        result = kwargs['arg1'] + kwargs['arg2']
        kwargs['result'] = result
        return super(PartialView, self).get_context_data(**kwargs)

if you are using class-based views.

Add it to urls.py:

url(r'^partial-view/(?P<arg1>\w+)/(?P<arg2>\w+)/$',
    partial_view,
    name='partial_view'),

or:

url(r'^partial-view/(?P<arg1>\w+)/(?P<arg2>\w+)/$',
    PartialView.as_view(),
    name='partial_view'),

In your template:

{% load render_partial %}
{% with some_var=2 %}
  {% render_partial 'partial_view' arg1=40 arg2=some_var %}
{% endwith %}

The render_partial tag would be rendered to:

<p>40 + 2 = 42</p>

Note that the with tag above is not required for render_partial to work. It is used to show that render_partial accepts variables. Every argument will be evaluated against context except for the names of any keyword arguments.

If you don’t want to expose your partial view in urls.py, you can also use fully qualified dot separated view name:

{% render_partial 'partial_test.views.PartialView' arg1=40 arg2=some_var %}
{% render_partial 'partial_test.views.partial_view' arg1=40 arg2=some_var %}

IMPORTANT: the calling template must receive a context variable called request containing the original HttpRequest. Don’t forget to add 'django.template.context_processors.request' to TEMPLATES['OPTIONS']['context_processors'].

Adapted from https://djangosnippets.org/snippets/1568/

Metadata

Release files for django-render-partial 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-render-partial 0.4
File Size Uploaded Provenance
django-render-partial-0.4.tar.gz 3.3 kB Without provenance Details

Release files / django-render-partial-0.4.tar.gz

Download URL django-render-partial-0.4.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7834485bbf061ee7c4f3e0d32257b5be3214bf8698a51638383ff754a08fc1e5
BLAKE2b-256 checksum
How to use checksums
d2bceafbab58dabd9e72e4a375646d6231b27df38d7cc92066de3b4fa9f8fe9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Security for django-render-partial 0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page