Path duplication in href

I'm new to Django and I'm trying to create web viewer for myself that browses static folder to open subfolders and .mp4 files. Problem occurs when I open second child of static folder: links break and start duplicating path.


Static folder structure:

- static folder
    - folder
    - videos

When root and first child folders are viewed, all HTML links work as needed and lead to next subfolders or files (links look like localhost:8000/videos/videos_1). When second child folder is viewed, it's content is displayed, but all links are broken, for example when folder videos_1 is viewed, links look like localhost:8000/videos/videos/videos_1/videos_1_1, however, when HTML is inspected, link is <a href="videos/videos_1/videos_1_1"></a>.

urlpatterns = [
    path('', folderViewer, name='files'),
    path('<path:kw>', folderViewer),]

def folderViewer(request, kw=''):

    path = os.path.join(STATIC_URL, kw)

    if os.path.isdir(path):
        files = os.listdir(path)
        paths_files = []
        for i in range(len(files)):
            paths_files.append([kw + '/' + files[i], files[i]])
        context = {
            'files': files,
            'paths_files': paths_files,

        return render(request, 'files.html', context)


    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    {% for i in paths_files %}
            <a href="{{ i.0 }}">{{ i.1 }}</a>
    {% endfor %}
Back to Top