Home > OS >  TypeError: render() missing 1 required positional argument: 'template_name'
TypeError: render() missing 1 required positional argument: 'template_name'

Time:03-29

I created simple form register user but something is wrong. This is my django project:

settings.py enter image description here

account/urls.py enter image description here

forms.py enter image description here

views.py enter image description here

Directories: enter image description here

error: enter image description here enter image description here

I don't understand this issue. I use render(request, 'name_template', {}) but django request name_template. What did I do wrong?

Sorry for my english but I still learn ;)

CodePudding user response:

in your path it should be

path('register/, views.register, ....)

CodePudding user response:

Could you check your TEMPLATES section in settings.py. It looks something like this:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'APP_DIRS': True,
    },
]

Check if you have path specified to your templates in 'DIR' key. If not, then add specified path to your templates folder.

TEMPLATES_DIR = os.path.join(BASE_DIR, 'account','templates')

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'APP_DIRS': True,
        'DIR': [TEMPLATES_DIR,]
    },
]

Documentation https://docs.djangoproject.com/en/4.0/ref/settings/#templates

CodePudding user response:

you're mapped a wrong view inside urls.py

path('register/', views.render, name='register'),

Change it to

path('register/', views.register, name='register'),
  • Related