Plugin – lektor-webdav 0.1.1.post5

Lektor plugin to get a list of files from a WebDAV server

Project links

GitHub Statistics


Version: 0.1.1.post5

Author: Amin Mesbah


content, Jinja filters, Jinja globals, remote content, setup-env, and WebDAV

View all tags.

Project Description

Lektor WebDAV Plugin

PyPI version

Get a list of files hosted on a WebDAV server for use in your Lektor templates.


mkdir packages
cd packages
git clone

I'll try to set this up soon so it can be installed properly with lektor plugins add.


For each WebDAV server you want to use, add a section in configs/webdav.ini:

url = https://my.webdav.domain/photography/
username =
passcmd = pass my_webdav_server

Replace 'photos' with whatever label you want for this particular webdav server.


Option Description
url URL of your WebDAV folder
username Username with which to authenticate with the WebDAV server
passcmd A command that will return your WebDAV password as a UTF-8 string

Use In Templates

This plugin exposes the following for use in Jinja2 templates:


  • webdav_ls_files
    • Return a list of all files (not folders) in a WebDAV directory. The files are returned in the form of a list of WebdavFile instances.
    • Parameters:
      • webdav_id. This is the name you chose as the section title in webdav.ini ('photos' in the above snippet).
      • path (optional). If you want to look in a subfolder of your WebDAV folder, pass its name in here.
  • webdav_ls_file_names
    • Same as webdav_ls_files, but only return the names.
  • webdav_ls_file_paths
    • Same as webdav_ls_files, but only return the paths.


  • WebdavFile: A named tuple that holds information about a file.
    • path
      • The full path of the file with the WebDAV server's URL as its root.
      • Example: '/photographs/my_photograph_of_a_wall.jpg'
    • name
      • Just the name of the file itself.
      • Example: 'my_photograph_of_a_wall.jpg'
    • content_type
      • Filetype metadata supplied by the WebDAV server.
      • Example: 'images/jpeg'


  • webdav_zip
    • Jinja2 doesn't have a zip filter, so I included one here since I needed to pair up my photos with generated thumbnails (see example below).
    • Usage: {{ zipped_iterator_ab = iterator_a|zip(iterator_b) }}


I made this because I wanted to make a photo gallery on my blog. I already had a webDAV server through my Fastmail account, and I wanted to host the images there.

My full site configuration can be found here, but here are the main bits:


My webdav.ini looks like this:

url =
username =
passcmd = pass sync/fastmail_webdav

I using pass to manage my passwords, so I invoke it in passcmd.


The template for my photography page looks like this:

{% extends "layout.html" %}
{% block body %}
<section class="photos">
<div class="photo-list">
{% set photo_host_url = bag('photo_list', 'host_url') %}
{% set thumb_dimension = bag('photo_list', 'thumb_dimension') %}
    for photo_file_name, thumbnail_file_name
    in (
        |webdav_zip(webdav_ls_file_names('photography', 'thumbnails')
    {% set photo_url = photo_host_url + photo_file_name %}
    {% set thumb_url = photo_host_url + 'thumbnails/' + thumbnail_file_name %}
    <div class="photo">
    <a href="{{ photo_url }}">
        <img src="{{ thumb_url }}" width="{{ thumb_dimension }}" height="{{ thumb_dimension }}"/>
{% endfor %}
{% endblock %}

I get a list of my WebDAV hosted photos and a list of pre-generated thumbnails. Then I zip them together with webdav_zip and iterate through them simultaneously.


My gallery page looks like this.

When I want to add more photos, I simply upload them to my WebDAV server, then run lektor build.