Django TypeError: render() got an unexpected keyword argument 'renderer'

前端 未结 3 1797
囚心锁ツ
囚心锁ツ 2020-11-30 08:12

I\'ve upgraded to Django 2.1, and I\'m seeing this error when I load the admin interface:

TypeError at /admin/foo/bar/1/change/

render() got an         


        
相关标签:
3条回答
  • 2020-11-30 08:53

    This is almost certainly because of this backwards-incompatible change in Django 2.1:

    • Support for Widget.render() methods without the renderer argument is removed.

    You may have subclassed django.forms.widgets.Widget in your code, or in the code of one of your dependencies. The code may look like this:

    from django.forms import widgets
    
    class ExampleWidget(widgets.Widget):
        def render(self, name, value, attrs=None):
            # ...
    

    You need to fix the method signature of render, so that it looks like this:

        def render(self, name, value, attrs=None, renderer=None):
    

    Have a look at the source code of widgets.Widget if you want to check.

    0 讨论(0)
  • 2020-11-30 08:56

    Django is looking for a default renderer which can be set in settings.py

    FORM_RENDERER = 'django.forms.renderers.DjangoTemplates'
    
    0 讨论(0)
  • 2020-11-30 09:03

    Its version and signature incompatibility issue. Go back to version - 2.0.8

    pip3 install Django==2.0.8

    0 讨论(0)
提交回复
热议问题