作者:华力 | 来源:互联网 | 2023-05-17 20:54
Mymodelslookslikethis:我的模型看起来像这样:classCar(models.Model):idmodels.UUIDField(primary_
My models looks like this:
我的模型看起来像这样:
class Car(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
name = models.CharField(max_length=200)
class Owner(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
car = models.ForeignKey(Car)
and a form that looks like this
和一个看起来像这样的形式
class CarForm (forms.ModelForm):
def __init__(self, *args, **kwargs):
super(CarForm, self).__init__(*args, **kwargs)
self.fields['car_name']=forms.CharField(widget=forms.TextInput(attrs={'autocomplete':'off'}),label='', required=False)
self.fields['person_name']=forms.CharField(widget=forms.TextInput(attrs={'autocomplete':'off'}),label='', required=False)
So when the user goes to my index file he find two forms, one for his name and one for the car's name which when submitted will be created in the database then.
因此,当用户访问我的索引文件时,他会找到两个表单,一个用于他的名字,另一个用于汽车的名称,然后在数据库中创建。
So now I am in the shell and want to test that and I'm not sure what the correct sytnax is, I tried this:
所以现在我在shell中并且想要测试它并且我不确定正确的sytnax是什么,我试过这个:
respOnse= client.post('/', {'car_name':'something','person_name':'something'})
but I always get a
但我总是得到一个
IndexError: list index out of range
IndexError:列表索引超出范围
What does that mean? Or what's the correct syntax to run the tests?
那是什么意思?或者运行测试的正确语法是什么?
I also tried
我也试过了
respOnse= client.post('/', {'id_car_name':'something','id_first_name':'something'})
Since these are the ids that django creates in the homepage, but didn't work
因为这些是django在主页中创建的ID,但是没有用
1 个解决方案