djangodjango-oscar

Problem Extending Django-Oscar's layout.html


The problem appeared after I added a template to a minimal webapp. The template extends django-oscar's layout.html. Nothing else in the project extends layout.html.

My goal is simply to be able to use django-oscar templates to form the basis of web pages in my webapp. For some reason I am having no end of issues. This is only the latest error message. I have been struggling with this for days! When I resolve one issue, another shows up.

I made a minimal git repo for this problem: https://github.com/mslinn/django_oscar_problem The repo has a requirements.txt file in case anyone wants to install the PIP modules necessary run the program.

I tried to ensure that I had the simplest possible project that shows the problem. In README.md I show the complete error message displayed in the web browser.

# /templates/welcome.html

{% extends 'oscar/layout.html' %}
... etc ...
# main/urls.py

from django.urls import include, path
from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, 'home'),
    path('admin/', admin.site.urls, 'admin'),
    path('hello/', views.hello, 'hello'),

    path('', include(apps.get_app_config('oscar').urls[0])),
]
# main/views.py

from django.shortcuts import render

def home(request):
    return render(request, "welcome.html", {})

I then ran the webapp with:

$ ./manage.py runserver

The error message in the web browser after visiting http://localhost:8000 is:

ValueError at /

dictionary update sequence element #0 has length 1; 2 is required

Request Method:     GET
Request URL:    http://localhost:8000/
Django Version:     3.1.6
Exception Type:     ValueError
Exception Value:

dictionary update sequence element #0 has length 1; 2 is required

Solution

  • The problem is here:

    urlpatterns = [
        path('', views.home, 'home'),
        path('admin/', admin.site.urls, 'admin'),
        path('hello/', views.hello, 'hello'),
    
        path('', include(apps.get_app_config('oscar').urls[0])),
    ]
    

    The arguments you're passing to path() are not quite right. The signature for path is:

    path(route, view, kwargs=None, name=None)
    

    i.e., the third positional argument is expected to be kwargs passed to the view function - but you've passed a string instead, which is what causes the somewhat obscure error. I think you intend this to be the name, in which case you need to supply that as a named argument, i.e.,:

    urlpatterns = [
        path('', views.home, name='home'),
        path('admin/', admin.site.urls, name='admin'),
        path('hello/', views.hello, name='hello'),
    
        path('', include(apps.get_app_config('oscar').urls[0])),
    ]
    

    Note that this then results in a new TemplateDoesNotExist error in your sample repo - this is because the location of the templates directory is not somewhere that Django knows to look. You can fix this by adding the path to that directory to the DIRS configuration in your template settings, which is currently set to [].