2017-07-29 92 views
3

我對Django有問題。我試圖在Django中創建第二個頁面,但得到TypeError。我需要幫助找到我犯了錯誤的地方。我試圖閱讀文檔,但現在對我來說很難。Django __init __()需要1個位置參數,但有2個被給出

__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') 
+0

添加完整的回溯與Django的版本,你是運用 –

回答

7

嘗試添加as_view和更好地展示完整的錯誤跟蹤

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