这是怎么了?
错误:文件“ /Users/user/Desktop/Dp1/project6/project6/urls.py”,行 18,在 从myapp6导入视图文件“ /Users/user/Desktop/Dp1/project6/myapp6/views.py”,第2行,在 从myapp6.forms导入UserForm,UserProfileInfoForm文件“ /Users/user/Desktop/Dp1/project6/myapp6/forms.py”,第15行,在 class UserProfileInfoForm(forms.ModelForm):文件“ /Users/user/miniconda3/envs/Djangoenv/lib/python3.7/site-packages/django/forms/models.py”, 第266行,新建 引发FieldError(message)django.core.exceptions.FieldError:为UserProfileInfo指定的未知字段(profile_pic)
models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class UserProfileInfo(models.Model):
user = models.OneToOneField(User,on_delete='models.PROTECT')
portfolio_site = models.URLField(blank=True)
portfolio_pic = models.ImageField(upload_to='profile_pics',blank=True)
def __str__(self):
return self.user.username
forms.py
from django import forms
from django.contrib.auth.models import User
from myapp6.models import UserProfileInfo
class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
class Meta():
model = User
fields = ('username','email','password',)
class UserProfileInfoForm(forms.ModelForm):
class Meta():
model = UserProfileInfo
fields = ('portfolio_site','profile_pic')
答案 0 :(得分:0)
您在UserProfileInfo模型中具有字段Portfolio_pic,但是在UserProfileInfoForm中,您具有profile_pic表单字段,该字段应为Portfolio_pic。
答案 1 :(得分:0)
改变这个:
class UserProfileInfoForm(forms.ModelForm):
class Meta():
model = UserProfileInfo
fields = ('portfolio_site','portfolio_pic')
为此:
class UserProfileInfoForm(forms.ModelForm):
class Meta():
model = UserProfileInfo
fields = ('portfolio_site','profile_pic')