from django import forms
class UserProfileForm(forms.Form):
first_name = models.CharField(max_length=20, widget=forms.TextInput(attrs={'placeholder': 'First Name'})
last_name = models.CharField(max_length=20, widget=forms.TextInput(attrs={'placeholder': 'Last Name'})
address = models.CharField(max_length=75, widget=forms.TextInput(attrs={'placeholder': 'Address'})
address2 = models.CharField(max_length=75, widget=forms.TextInput(attrs={'placeholder': 'Address 2'})
postcode = models.CharField(max_length=10, widget=forms.TextInput(attrs={'placeholder': 'Postcode'})
phone = models.IntegerField(max_length=15, widget=forms.TextInput(attrs={'placeholder': 'Mobile Number'})
SyntaxError位于/ 语法无效(forms.py,第6行)
这应该是男生的错误,但似乎无法解决。
答案 0 :(得分:1)
在每一行中,打开两个括号:
但是在该行的末尾,您只需要关闭一个括号,因此在每一行中,您都需要添加一个额外的结束括号。
您还使用models.
代替了forms.
。这些是不同的,因为models.
用于数据库列,而forms.
以(HTML)格式封装项目。
from django import forms
class UserProfileForm(forms.Form):
first_name = forms.CharField(max_length=20, widget=forms.TextInput(attrs = {'placeholder': 'First Name'}))
last_name = forms.CharField(max_length=20, widget=forms.TextInput(attrs = {'placeholder': 'Last Name'}))
address = forms.CharField(max_length=75, widget=forms.TextInput(attrs = {'placeholder': 'Address'}))
address2 = forms.CharField(max_length=75, widget=forms.TextInput(attrs = {'placeholder': 'Address 2'}))
postcode = forms.CharField(max_length=10, widget=forms.TextInput(attrs = {'placeholder': 'Postcode'}))
phone = forms.IntegerField(widget=forms.TextInput(attrs = {'placeholder': 'Mobile Number'}))