Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- windows apache wsgi 에러
- 원격 연결 포트 포워딩
- 2961 java
- Problems occurred while performing provisioning operation
- django
- 18233 java
- 18233 비트마스킹
- 2961 도영이가 만든 맛있는 음식
- APPEND_SLASH = FALSE
- django 웹 페이지
- django 프로젝트 시작
- windows 원격 연결 설정
- 18233 러버덕
- 2643 java
- django httpd error
- java di
- 2643 색종이 올려 놓기
- 1188 음식 평론가
- 14711 java
- apache pythonpath
- 14711 타일 뒤집기
- django The requested operation has failed!
- 공유기 원격 설정
- django settings.py
- django apache deploy error
- The requested operation has failed!
- django windows 배포 에러
- 2661 java
- 1188 java
- 2661 좋은 수열
Archives
라이브러리는 도서관 아닌가요
AttributeError at /main/'Form' object has no attribute 'save' 본문
Django/Django Trouble Shooting
AttributeError at /main/'Form' object has no attribute 'save'
veryhi 2021. 10. 7. 16:26Django에서 자주 만나는 에러인 AttributeError
아래의 경우는 form 작성 때 발생한 문제이다.
예를 들어, form의 클래스를 상속 받을 때 잘못되었을 경우가 있다.
from django import forms
from .models import Content
class ContentForm(forms.Form):
def __init(self, *args, **kwargs):
super(ContentForm, self).__init__(*args, **kwargs)
self.fields['content'].widget.attrs.update({
'class': 'form-control',
'autofocus': True
})
class Meta:
model = Content
fields = ['content']
아래와 같이 고쳐주면 된다.
from django import forms
from .models import Content
class ContentForm(forms.ModelForm): # 바뀐 부분
def __init(self, *args, **kwargs):
super(ContentForm, self).__init__(*args, **kwargs)
self.fields['content'].widget.attrs.update({
'class': 'form-control',
'autofocus': True
})
class Meta:
model = Content
fields = ['content']
AttributeError가 발생할 때 클래스 상속을 잘못 받았는지도 한 번 점검해보도록 하자.
'Django > Django Trouble Shooting' 카테고리의 다른 글
RuntimeError: You called this URL via PUT, but the URL doesn't end in a slash and you have APPEND_SLASH set. (0) | 2023.01.30 |
---|---|
Windows Apache Django wsgi - 배포 에러 (0) | 2022.11.17 |
Django 404 page debug false, static media 미적용 (0) | 2021.12.19 |
ModuleNotFoundError: No module named 'ipware' 에러 (0) | 2021.12.16 |
Comments