### Install django-distill Source: https://github.com/meeb/django-distill/blob/master/README.md Installs the django-distill package using pip. This is the first step to integrate django-distill into your Django project. ```bash #!/bin/bash $ pip install django-distill ``` -------------------------------- ### Running Django Distill Tests (Bash) Source: https://github.com/meeb/django-distill/blob/master/README.md Provides the command to execute the test suite for `django-distill`. After cloning the repository and installing dependencies from `requirements.txt`, this script can be run to verify the library's functionality. ```bash # ./run-tests.py ``` -------------------------------- ### Test Publishing Configuration with distill-test-publish Command Source: https://github.com/meeb/django-distill/blob/master/README.md The `distill-test-publish` command verifies the publishing target settings by connecting, authenticating, uploading a test file, verifying its existence via `PUBLIC_URL`, and then deleting it. This command has no arguments and is useful for ensuring correct publishing setup. ```bash #!/bin/bash ./manage.py distill-test-publish [optional destination here] ``` -------------------------------- ### Configure Google Cloud Storage Backend for django-distill Source: https://context7.com/meeb/django-distill/llms.txt This configuration sets up django-distill to publish static sites to Google Cloud Storage. It requires specifying the storage engine, public URL, bucket name, and optionally, the path to service account credentials. The `django-distill[google]` package must be installed. ```python # settings.py DISTILL_PUBLISH = { 'default': { 'ENGINE': 'django_distill.backends.google_storage', 'PUBLIC_URL': 'https://storage.googleapis.com/my-bucket-name/', 'BUCKET': 'my-bucket-name', # Optional: Path to service account credentials JSON 'JSON_CREDENTIALS': '/path/to/service-account-credentials.json', }, } # Alternative: Use environment variable for credentials # export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json" # Install with: pip install django-distill[google] ``` -------------------------------- ### Django Distill URL Configuration for Static File Generation (Python) Source: https://github.com/meeb/django-distill/blob/master/README.md Illustrates how to define a URL pattern in Django's `urls.py` using `distill_path` that can be targeted by `render_single_file`. This setup allows `django-distill` to generate static HTML files corresponding to dynamic views, including parameters like `blog_id` and `blog_slug`. ```python from django.urls import path from django_distill import distill_path from .views import PostView # Assuming PostView is defined elsewhere urlpatterns = [ # ... other url patterns ... distill_path('post/_.html', PostView.as_view(), name='blog-post', distill_func=get_all_blogposts), # distill_func is optional # ... other url patterns ... ] ``` -------------------------------- ### Python: Django Settings for Internationalization Source: https://github.com/meeb/django-distill/blob/master/README.md Provides an example of how to configure Django settings for internationalization when using django-distill. This includes setting USE_I18N and defining DISTILL_LANGUAGES. ```python USE_I18N = True DISTILL_LANGUAGES = [ 'en', 'fr', 'de', ] ``` -------------------------------- ### Configure Microsoft Azure Storage Backend for django-distill Source: https://context7.com/meeb/django-distill/llms.txt This configuration enables django-distill to publish static content to Microsoft Azure Blob Storage, specifically using the `$web` container for static website hosting. It requires the `azure-storage-blob` library and the Azure connection string. The `django-distill[microsoft]` package must be installed. ```python # settings.py DISTILL_PUBLISH = { 'default': { 'ENGINE': 'django_distill.backends.microsoft_azure_storage', 'PUBLIC_URL': 'https://mystorageaccount.z13.web.core.windows.net/', 'CONNECTION_STRING': 'DefaultEndpointsProtocol=https;AccountName=mystorageaccount;AccountKey=your-account-key;EndpointSuffix=core.windows.net', }, } # Install with: pip install django-distill[microsoft] ``` -------------------------------- ### Configure Internationalization (i18n) Support in django-distill Source: https://context7.com/meeb/django-distill/llms.txt This setup enables django-distill to generate multi-language static sites by leveraging Django's `i18n_patterns`. URLs will be prefixed with language codes, and separate static files will be generated for each configured language. This requires setting `USE_I18N` and `LANGUAGE_CODE` in `settings.py` and defining `DISTILL_LANGUAGES`. ```python # settings.py USE_I18N = True LANGUAGE_CODE = 'en' DISTILL_LANGUAGES = [ 'en', 'fr', 'de', 'es', ] # urls.py from django.conf.urls.i18n import i18n_patterns from django_distill import distill_path def get_pages(): return None urlpatterns = i18n_patterns( distill_path('about/', AboutView.as_view(), name='about', distill_func=get_pages), distill_path('contact/', ContactView.as_view(), name='contact', distill_func=get_pages), ) # Generated files: # /en/about/index.html # /fr/about/index.html # /de/about/index.html # /es/about/index.html # /en/contact/index.html # /fr/contact/index.html # ... ``` -------------------------------- ### Get all distilled URLs with distilled_urls Source: https://context7.com/meeb/django-distill/llms.txt The `distilled_urls` function returns a generator of all URLs registered with django-distill. This is useful for generating sitemaps or URL listings. Each iteration yields a tuple containing the generated URI and its corresponding file path on disk. ```python from django_distill import distilled_urls # Example usage (within a Django management command or script): # for uri, filename in distilled_urls(): # print(f"URI: {uri}, File: {filename}") ``` -------------------------------- ### Bash: Generating a static Django site with distill-local Source: https://github.com/meeb/django-distill/blob/master/README.md Illustrates the command-line usage of the `distill-local` management command provided by django-distill. This command generates a complete static version of the Django site. ```bash ./manage.py distill-local [optional /path/to/export/directory] ``` -------------------------------- ### Publish Static Site with distill-publish Command Source: https://github.com/meeb/django-distill/blob/master/README.md The `distill-publish` command synchronizes the generated static site to a remote location. It handles full synchronization, including removing old files and uploading new ones. The site is built locally first in a temporary directory. Supports various flags for customization like `--collectstatic`, `--quiet`, `--force`, `--exclude-staticfiles`, `--skip-verify`, `--ignore-remote-content`, `--parallel-publish`, `--parallel-render`, and `--generate-redirects`. ```bash #!/bin/bash ./manage.py distill-publish [optional destination here] ``` -------------------------------- ### Google Cloud Storage Publishing Target Configuration (Python) Source: https://github.com/meeb/django-distill/blob/master/README.md Details the configuration for publishing static files to a Google Cloud Storage bucket using `django-distill`. This requires `google-api-python-client` and `google-cloud-storage`. Key settings include `ENGINE`, `PUBLIC_URL`, `BUCKET`, and an optional `JSON_CREDENTIALS` path for authentication. ```python DISTILL_PUBLISH_TARGETS = { 'some-google-storage-bucket': { 'ENGINE': 'django_distill.backends.google_storage', 'PUBLIC_URL': 'https://storage.googleapis.com/[bucket.name.here]/', 'BUCKET': '[bucket.name.here]', 'JSON_CREDENTIALS': '/path/to/some/credentials.json', # Optional }, } ``` -------------------------------- ### Generate Static Site Locally with `distill-local` Source: https://context7.com/meeb/django-distill/llms.txt The `distill-local` Django management command generates a complete static site to a specified local directory. It can optionally run `collectstatic`, handle redirects, exclude static files, and use parallel rendering for faster generation. Options like `--force` and `--quiet` are available for automation and reduced output. ```bash # Basic usage - generates site to DISTILL_DIR or specified path ./manage.py distill-local /path/to/output # Run collectstatic first, then generate site ./manage.py distill-local --collectstatic /path/to/output # Generate without prompts (for CI/CD) ./manage.py distill-local --force /path/to/output # Parallel rendering for faster generation ./manage.py distill-local --parallel-render 4 /path/to/output # Skip static files, only render Django views ./manage.py distill-local --exclude-staticfiles /path/to/output # Generate static redirects from django.contrib.redirects ./manage.py distill-local --generate-redirects /path/to/output # Quiet mode - minimal output ./manage.py distill-local --quiet --force /path/to/output ``` -------------------------------- ### Amazon S3 Publishing Target Configuration (Python) Source: https://github.com/meeb/django-distill/blob/master/README.md Provides a configuration dictionary for `django-distill` to publish static files to an Amazon S3 bucket. It requires the `boto3` library and specifies essential parameters like `ENGINE`, `PUBLIC_URL`, `ACCESS_KEY_ID`, `SECRET_ACCESS_KEY`, and `BUCKET`. Optional parameters like `ENDPOINT_URL` and `DEFAULT_CONTENT_TYPE` are also included. ```python DISTILL_PUBLISH_TARGETS = { 'some-s3-container': { 'ENGINE': 'django_distill.backends.amazon_s3', 'PUBLIC_URL': 'http://.../', 'ACCESS_KEY_ID': '...', 'SECRET_ACCESS_KEY': '...', 'BUCKET': '...', 'ENDPOINT_URL': 'https://.../', # Optional 'DEFAULT_CONTENT_TYPE': 'application/octet-stream', # Optional }, } ``` -------------------------------- ### Define Blog Post Detail URL with Distill Source: https://github.com/meeb/django-distill/blob/master/README.md Defines the URL pattern for individual blog post pages using `distill_path`. This pattern includes named parameters for the post ID and title, and uses a distillation function to provide data for generating static files. ```python from django_distill import distill_path from blog.views import PostView from blog.models import Post def get_all_blogposts(): for post in Post.objects.all(): yield {'blog_id': post.id, 'blog_title': post.title} urlpatterns = ( distill_path('post/-.html', PostView.as_view(), name='blog-post', distill_func=get_all_blogposts), ) ``` -------------------------------- ### Configure Optional Settings for django-distill Source: https://context7.com/meeb/django-distill/llms.txt This section details optional settings for customizing django-distill's behavior, including the output directory for `distill-local`, options to skip specific directories during static file collection, language support for i18n generation, and advanced configurations like custom renderer classes. It also includes essential Django settings for static and media files. ```python # settings.py # Default output directory for distill-local command DISTILL_DIR = '/var/www/static-site' # Skip copying admin static files (default: True) DISTILL_SKIP_ADMIN_DIRS = True # Skip specific directories in static files DISTILL_SKIP_STATICFILES_DIRS = [ 'debug_toolbar', 'rest_framework', 'some_unused_app', ] # Languages for i18n static generation DISTILL_LANGUAGES = ['en', 'fr', 'de'] # Custom renderer class (advanced usage) DISTILL_RENDERER = 'myapp.renderers.CustomDistillRender' # Required Django settings for static files STATIC_URL = '/static/' STATIC_ROOT = '/path/to/collected/static/' MEDIA_URL = '/media/' MEDIA_ROOT = '/path/to/media/files/' # Disable SSL redirect for local development with HTTPS SECURE_SSL_REDIRECT = False ``` -------------------------------- ### Publish Static Site with `distill-publish` Source: https://context7.com/meeb/django-distill/llms.txt The `distill-publish` Django management command generates and publishes a static site to a configured cloud storage backend. It performs full synchronization, including uploading new/changed files and deleting orphaned remote files. Options for parallel publishing, skipping verification, and ignoring remote content are available. ```bash # Publish to default backend ./manage.py distill-publish # Publish to a specific named backend ./manage.py distill-publish some-other-target # Parallel publishing for faster uploads ./manage.py distill-publish --parallel-publish 4 # Skip file verification after upload ./manage.py distill-publish --skip-verify # Upload all files without checking remote state (faster for full rebuilds) ./manage.py distill-publish --ignore-remote-content # Combined options for CI/CD ./manage.py distill-publish --collectstatic --force --parallel-render 4 --parallel-publish 4 ``` -------------------------------- ### Configure Amazon S3 Backend for Publishing Source: https://context7.com/meeb/django-distill/llms.txt This Python configuration in `settings.py` sets up django-distill to publish static sites to Amazon S3 buckets. It requires the `boto3` library and an S3 bucket configured for static website hosting. The configuration includes credentials, bucket name, and public URL, with an option for S3-compatible services. ```python # settings.py DISTILL_PUBLISH = { 'default': { 'ENGINE': 'django_distill.backends.amazon_s3', 'PUBLIC_URL': 'https://my-bucket.s3.amazonaws.com/', 'ACCESS_KEY_ID': 'AKIAIOSFODNN7EXAMPLE', 'SECRET_ACCESS_KEY': 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', 'BUCKET': 'my-static-site-bucket', }, # Optional: Use S3-compatible services (MinIO, DigitalOcean Spaces, etc.) 'digitalocean': { 'ENGINE': 'django_distill.backends.amazon_s3', 'PUBLIC_URL': 'https://my-space.nyc3.digitaloceanspaces.com/', 'ACCESS_KEY_ID': 'your-access-key', 'SECRET_ACCESS_KEY': 'your-secret-key', 'BUCKET': 'my-space', 'ENDPOINT_URL': 'https://nyc3.digitaloceanspaces.com', }, } # Install with: pip install django-distill[amazon] ``` -------------------------------- ### Configure URL routing with distill_path Source: https://github.com/meeb/django-distill/blob/master/README.md Demonstrates how to replace Django's standard `path` function with `distill_path` in your `urls.py`. This function allows for static site generation by specifying `distill_func` and optionally `distill_file` arguments. ```python # Replaces the standard django.conf.path, identical syntax from django_distill import distill_path # Example usage: # urlpatterns = [ # distill_path('some-url//', 'myapp.views.some_view', distill_func=myapp.views.some_view_context, distill_file='some-other-name.html'), # ] ``` -------------------------------- ### Configure Google Cloud Storage Backend for Publishing Source: https://context7.com/meeb/django-distill/llms.txt This Python configuration in `settings.py` sets up django-distill to publish static sites to Google Cloud Storage (GCS) buckets. It requires the `google-api-python-client` and `google-cloud-storage` libraries. The GCS bucket must be configured to host a public static website. ```python # settings.py # Requires: pip install google-api-python-client google-cloud-storage # Ensure your GCS bucket is configured for static website hosting. # Authentication is typically handled via environment variables or service account keys. DISTILL_PUBLISH = { 'default': { 'ENGINE': 'django_distill.backends.google_cloud_storage', 'BUCKET': 'your-gcs-bucket-name', 'PUBLIC_URL': 'https://storage.googleapis.com/your-gcs-bucket-name/', # Optional: Specify a project ID if not using default from environment # 'PROJECT': 'your-gcp-project-id', } } ``` -------------------------------- ### Python: Using distill_path for Internationalized URLs Source: https://github.com/meeb/django-distill/blob/master/README.md Demonstrates how to configure internationalized URLs using django-distill's distill_path function in conjunction with Django's i18n_patterns. This allows for generating static sites in multiple languages. ```python from django.conf.urls.i18n import i18n_patterns from django_distill import distill_path urlpatterns = i18n_patterns( distill_path('some-file.html', SomeView.as_view(), name='i18n-view', distill_func=some_func ) ) ``` -------------------------------- ### Using distill_url for Older Django Versions Source: https://github.com/meeb/django-distill/blob/master/README.md Shows how to use `distill_url` for compatibility with older Django versions (1.x series). This function replaces Django's `url` function and enables static file generation. ```python from django_distill import distill_url from some_app.views import SomeView def some_func(): pass urlpatterns = ( distill_url(r'some/regex', SomeView.as_view(), name='url-view', distill_func=some_func), ) ``` -------------------------------- ### Define Blog Post Index URL with Distill Source: https://github.com/meeb/django-distill/blob/master/README.md Defines the URL pattern for the blog index page using `distill_path`. It specifies the URL path, the associated view, a name for the URL, and an optional distillation function and file name. ```python from django_distill import distill_path from blog.views import PostIndex urlpatterns = ( distill_path('', PostIndex.as_view(), name='blog-index', distill_file='index.html'), ) ``` -------------------------------- ### Override Static File Path with Parameters Source: https://github.com/meeb/django-distill/blob/master/README.md Illustrates how to customize the output file path for a statically generated page using the `distill_file` parameter with Python string formatting. This allows for dynamic file naming based on URL parameters. ```python from django_distill import distill_path from blog.views import PostView from blog.models import Post def get_all_blogposts(): for post in Post.objects.all(): yield {'blog_id': post.id, 'blog_title': post.title} urlpatterns = ( distill_path('post/-.html', PostView.as_view(), name='blog-post', distill_func=get_all_blogposts, distill_file="post/{blog_id}-{blog_title}.html") ) ``` -------------------------------- ### Define Posts by Year URL with Distill Source: https://github.com/meeb/django-distill/blob/master/README.md Defines the URL pattern for viewing posts by year using `distill_path`. This pattern uses a positional parameter for the year and a distillation function to provide the years for which static files should be generated. ```python from django_distill import distill_path from blog.views import PostYear def get_years(): return (2014, 2015) urlpatterns = ( distill_path('posts-by-year//', PostYear.as_view(), name='blog-year', distill_func=get_years), ) ``` -------------------------------- ### Python: Generating a list of distilled URLs Source: https://github.com/meeb/django-distill/blob/master/README.md Shows how to use the distilled_urls() helper function from django-distill to retrieve a list of all URIs that will be generated by the static site build process. This is useful for creating sitemaps or other URL listings. ```python from django_distill import distilled_urls for uri, file_name in distilled_urls(): # URI is the generated, complete URI for the page print(uri) # for example: /blog/my-post-123/ # file_name is the actual file name on disk, this may be None or a string print(file_name) # for example: /blog/my-post-123/index.html ``` -------------------------------- ### Using distill_re_path for Regex URL Patterns Source: https://github.com/meeb/django-distill/blob/master/README.md Demonstrates the usage of `distill_re_path` for defining URL patterns that use regular expressions. This function is a replacement for Django's `re_path` and allows for static file generation. ```python from django_distill import distill_re_path from some_app.views import SomeOtherView def some_other_func(): pass urlpatterns = ( distill_re_path(r'some/regex', SomeOtherView.as_view(), name='url-other-view', distill_func=some_other_func), ) ``` -------------------------------- ### Add django_distill to INSTALLED_APPS Source: https://github.com/meeb/django-distill/blob/master/README.md Configures your Django project's settings to include 'django_distill' in the INSTALLED_APPS list. This enables django-distill's features within your project. ```python INSTALLED_APPS = [ # ... other apps here ... 'django_distill', ] ``` -------------------------------- ### Render Single Static File with Django Source: https://context7.com/meeb/django-distill/llms.txt The `render_single_file` function from `django_distill.renderer` allows for on-demand rendering and writing of individual static files. This is useful for updating specific pages, like blog posts, after model saves or deletions, without regenerating the entire site. It can handle views with keyword arguments, positional arguments, and custom status codes. ```python from django.db.models.signals import post_save, post_delete from django.dispatch import receiver from django_distill.renderer import render_single_file from blog.models import Post OUTPUT_DIR = '/var/www/static-site' @receiver(post_save, sender=Post) def update_post_static_file(sender, instance, **kwargs): # Regenerate the individual post page after save render_single_file( OUTPUT_DIR, 'blog-post', # URL name from urls.py blog_id=instance.pk, blog_slug=instance.slug ) # Also regenerate the index page render_single_file(OUTPUT_DIR, 'blog-index') @receiver(post_delete, sender=Post) def regenerate_index_on_delete(sender, instance, **kwargs): # Regenerate index after post deletion render_single_file(OUTPUT_DIR, 'blog-index') # For views with positional arguments: render_single_file( OUTPUT_DIR, 'blog-year', 2024 # positional arg ) # For views with custom status codes: render_single_file( OUTPUT_DIR, 'not-found', status_codes=(200, 404) ) ``` -------------------------------- ### Register URL pattern for static generation with distill_path Source: https://context7.com/meeb/django-distill/llms.txt The `distill_path` function registers a URL pattern for static site generation. It replaces Django's `path()` with additional arguments `distill_func` and `distill_file` to control page generation and output file names. It supports parameterless URLs, named parameters, and positional parameters. ```python from django_distill import distill_path from blog.views import PostIndex, PostView, PostYear from blog.models import Post def get_index(): # For URLs with no parameters, return None return None def get_all_blogposts(): # Return an iterable of dictionaries for named URL parameters for post in Post.objects.all(): yield {'blog_id': post.id, 'blog_title': post.title} def get_years(): # Return simple values for positional URL parameters return (2014, 2015, 2016) urlpatterns = [ # Static index page - distill_func optional for parameterless URLs distill_path('', PostIndex.as_view(), name='blog-index', distill_func=get_index, distill_file='index.html'), # Blog posts with named parameters distill_path('post/-.html', PostView.as_view(), name='blog-post', distill_func=get_all_blogposts), # Year archive pages - URLs ending in / become /index.html distill_path('posts-by-year//', PostYear.as_view(), name='blog-year', distill_func=get_years), ] # Output files generated: # - /index.html # - /post/1-hello-world.html, /post/2-another-post.html, ... # - /posts-by-year/2014/index.html, /posts-by-year/2015/index.html, ... ``` -------------------------------- ### Control Skipping Admin Static Files with DISTILL_SKIP_ADMIN_DIRS Source: https://github.com/meeb/django-distill/blob/master/README.md The `DISTILL_SKIP_ADMIN_DIRS` boolean setting in `settings.py` controls whether static files in the `static/admin` directory are copied during publishing. The default is `True`, skipping these files as they are usually not needed for static sites. ```python DISTILL_SKIP_ADMIN_DIRS = True ``` -------------------------------- ### Configure Default Export Directory with DISTILL_DIR Source: https://github.com/meeb/django-distill/blob/master/README.md The `DISTILL_DIR` setting in `settings.py` specifies the default directory where the static site will be exported. This is a string value representing the file path. ```python DISTILL_DIR = '/path/to/export/directory' ``` -------------------------------- ### Generate Sitemap XML with Django Source: https://context7.com/meeb/django-distill/llms.txt This Python function generates a sitemap.xml file for a Django project. It iterates through URLs provided by `distilled_urls` and formats them into the sitemap structure. The output includes the location and last modification date for each URL. ```python def sitemap_view(request): urls = [] for uri, file_name in distilled_urls(): # uri: '/blog/my-post-123/' (URL path) # file_name: '/blog/my-post-123/index.html' (physical file, may be None) urls.append({ 'loc': f'https://example.com{uri}', 'lastmod': '2024-01-15', }) return render(request, 'sitemap.xml', {'urls': urls}) ``` -------------------------------- ### Configure Publishing Destinations with DISTILL_PUBLISH Source: https://github.com/meeb/django-distill/blob/master/README.md The `DISTILL_PUBLISH` setting in `settings.py` is a dictionary used to define multiple publishing destinations, similar to Django's `settings.DATABASES`. It supports a 'default' key and other custom target names, each with its own set of options. ```python DISTILL_PUBLISH = { 'default': { ... options ... }, 'some-other-target': { ... options ... }, } ``` -------------------------------- ### Specify Static Directories to Ignore with DISTILL_SKIP_STATICFILES_DIRS Source: https://github.com/meeb/django-distill/blob/master/README.md The `DISTILL_SKIP_STATICFILES_DIRS` setting in `settings.py` accepts a list of directory names within your `static/` directory that should be ignored during the publishing process. This is useful for excluding static files from unused apps that might be bundled by `collectstatic`. ```python DISTILL_SKIP_STATICFILES_DIRS = ['some_dir'] ``` -------------------------------- ### Render Single File with Django Signals (Python) Source: https://github.com/meeb/django-distill/blob/master/README.md Demonstrates how to use `django_distill.renderer.render_single_file` within a Django post_save signal to automatically update a static HTML file when a model instance changes. This function takes an output directory, a view name, and view arguments to generate the file. ```python from django.db.models.signals import post_save from django.dispatch import receiver from django_distill.renderer import render_single_file # Assuming SomeBlogPostModel is defined elsewhere # from .models import SomeBlogPostModel @receiver(post_save, sender=SomeBlogPostModel) def write_blog_post_static_file_post_save(sender, **kwargs): render_single_file( '/path/to/output/directory', 'blog-post-view-name', # This should match a name in urls.py blog_id=sender.pk, blog_slug=sender.slug ) ``` -------------------------------- ### Configure Languages for URL Rendering with DISTILL_LANGUAGES Source: https://github.com/meeb/django-distill/blob/master/README.md The `DISTILL_LANGUAGES` setting in `settings.py` is a list of language codes for which URLs should be rendered. This is relevant for internationalized sites and requires further configuration in the 'Internationalization' section. ```python DISTILL_LANGUAGES = [ 'en', 'fr', 'de', ] ``` -------------------------------- ### Register URL pattern with regex for static generation using distill_re_path Source: https://context7.com/meeb/django-distill/llms.txt The `distill_re_path` function registers a URL pattern using regex for static site generation. It functions identically to `distill_path` but utilizes regex patterns, similar to Django's `re_path()`, for more complex URL matching requirements. It supports named regex groups and positional regex groups. ```python from django_distill import distill_re_path from myapp.views import CategoryView, ArticleView def get_categories(): return ['technology', 'science', 'arts'] def get_articles(): # Return tuples for positional regex groups return [ ('technology', 'intro-to-python'), ('science', 'quantum-basics'), ] urlpatterns = [ distill_re_path(r'^category/(?P[w-]+)/$', CategoryView.as_view(), name='category-view', distill_func=get_categories), distill_re_path(r'^(?P[w-]+)/(?P
[w-]+)\.html$', ArticleView.as_view(), name='article-view', distill_func=get_articles), ] ``` -------------------------------- ### Disable SSL Redirect for Local HTTPS Development Source: https://github.com/meeb/django-distill/blob/master/README.md When developing locally with HTTPS, you might encounter a `CommandError` due to 301 redirects. Setting `SECURE_SSL_REDIRECT = False` in your `settings.py` can prevent this issue by disabling SSL redirection. ```python SECURE_SSL_REDIRECT = False ``` -------------------------------- ### Allow non-200 status codes for static pages with distill_status_codes Source: https://context7.com/meeb/django-distill/llms.txt The `distill_status_codes` parameter allows views returning non-200 status codes to be rendered as static pages. By default, only HTTP 200 responses are accepted. This parameter can be used to permit additional status codes, such as 404 for custom error pages. ```python from django_distill import distill_path from myapp.views import NotFoundView, GoneView def get_error_pages(): return None urlpatterns = [ # Generate a custom 404 page distill_path('404.html', NotFoundView.as_view(), name='not-found', distill_func=get_error_pages, distill_status_codes=(200, 404)), # Generate a custom 410 Gone page distill_path('gone.html', GoneView.as_view(), name='gone-page', distill_func=get_error_pages, distill_status_codes=(200, 410)), ] ``` -------------------------------- ### Display Relative Time with Django's Naturaltime Filter Source: https://github.com/meeb/django-distill/blob/master/tests/templates/humanize.html This snippet shows how to use the 'naturaltime' filter within a Django template. It assumes you have datetime objects named 'one_hour_ago' and 'nineteen_hours_ago' available in your template context. The filter converts these into human-readable strings. ```django {% load humanize %} * one hour ago naturaltime: {{ one_hour_ago|naturaltime }} * nineteen hours ago naturaltime: {{ nineteen_hours_ago|naturaltime }} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.