Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django __init__() takes 1 positional argument but 2 were given [closed]

I'm have a problem with Django. I'm trying to create a second page in Django but get TypeError. I need help finding where I made the mistake. I tried to read the documentation, but it's hard to me now.

__init__.py

default_app_config = 'page.apps.PageConfig'

urls.py

from django.conf.urls import url
from . import views

urlpatterns = [
    # url(r'^$', views.IndexView.as_view(), name='index' ),
    url(r'^$', views.IndexView, name='index'),
]

view.py

from django.views.generic import TemplateView
from libs.views import CachedViewMixin
from .models import Page


class IndexView(CachedViewMixin, TemplateView):
    template_name = 'main/index.html'
    config = None

model.py

from django.db import models
from django.utils.translation import ugettext_lazy as _, ugettext
from solo.models import SingletonModel


class Page(SingletonModel):
    updated = models.DateTimeField(_('change date'), auto_now=True)

    class Meta:
        default_permissions = ('change',)
        verbose_name = _('settings')

    def __str__(self):
        return ugettext('Home page')

apps.py

from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _


class PageConfig(AppConfig):
    name = 'page'
    verbose_name = _('Another page')
like image 335
Андрей Вершинин Avatar asked Dec 14 '22 21:12

Андрей Вершинин


1 Answers

Try add as_view and better to show full error trace

urlpatterns = [
    # url(r'^$', views.IndexView.as_view(), name='index' ),
    url(r'^$', views.IndexView.as_view(), name='index'),
    #                          ^^^^^^^^
]
like image 94
Brown Bear Avatar answered May 03 '23 14:05

Brown Bear