반응형
간단한 방명록 django : __init __ ()는 1 개의 위치 인자를 받지만 2 개가 주어졌습니다.
저는 Django를 처음 접했고 환경에 익숙해지기 위해 간단한 방명록 애플리케이션을 만들려고합니다. 다음과 같은 오류가 발생하지만 오류를 찾을 수 없습니다.
예외 값 : _ init _ ()는 1 개의 위치 인수를 사용하지만 2 개가 제공되었습니다.
from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin
class Bericht(models.Model):
titel = models.CharField(max_length=50)
auteur = models.ForeignKey(User, blank=True)
email = models.EmailField(max_length=75)
inhoud = models.TextField(max_length=10000, blank=True)
datum = models.DateTimeField(auto_now_add=True)
def __str__(self):
return str(self.auteur) + " : " + str(self.titel)
class Meta:
verbose_name_plural = "berichten"
class BerichtAdmin(admin.ModelAdmin):
list_display = ["auteur", "datum", "titel"]
list_filter = ["datum", "auteur"]
admin.site.register(Bericht, BerichtAdmin)
보기
from django.shortcuts import render
from django.views.generic import ListView
from Gastenboek.models import *
class BerichtListView(ListView):
model = Bericht.objects.all()
template_name = 'template/bericht_lijst.html'
paginate_by = 10
context_object_name = "bericht_lijst"
# Create your views here.
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Niels.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
(r"^(\d+)/$", 'Gastenboek.views.BerichtListView'),
(r"", 'Gastenboek.views.BerichtListView'),
)
역 추적
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.6.1
Python Version: 3.3.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Gastenboek')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "C:\Python33\lib\site-packages\django\core\handlers\base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
Exception Type: TypeError at /
Exception Value: __init__() takes 1 positional argument but 2 were given
urls.py에서 :
.as_view ()가 누락되었습니다.
다음으로 변경하십시오.
(r"^(\d+)/$", Gastenboek.views.BerichtListView.as_view()),
(r"", Gastenboek.views.BerichtListView.as_view()),
반응형
'Development Tip' 카테고리의 다른 글
AngularJS에서 필터링 된 결과 강조 (0) | 2021.01.05 |
---|---|
모바일보기에서만 div 태그를 숨기시겠습니까? (0) | 2021.01.05 |
Mailchimp의 API v3을 사용하여 목록에 구독자 추가 (0) | 2021.01.05 |
cordova run with ios error .. Error code 65 for command : xcodebuild with args : (0) | 2021.01.05 |
Java 컬렉션과 컬렉션의 차이점 (0) | 2021.01.05 |