python - django form doesn't show up or object takes no parameters error -
i add form on website firms list themselves. it's kind of local business directory wanted build django. when try show form on "add-business" page 2 different results.
the first result is: if use {{ form.as_p }}
doesn't show form.
the second result is: if try build form own html inputs, says object() takes no parameters
, pointing @ request.post
within view (form = addbusinessform(request.post)
) can see below.
i don't know wrong. view same django docs.
my model :
class firma(models.model): user = models.foreignkey(user, on_delete=models.cascade) firm_name = models.charfield(max_length=120) firm_adress = models.charfield(max_length=200) firm_city = models.charfield(max_length=100) firm_desc = models.textfield(max_length=2000) firm_email = models.emailfield(max_length=80, unique=true,validators=[validate_email, ]) firm_phone = models.charfield(max_length=20) firm_website = models.charfield(max_length=60, validators=[urlvalidator()]) firm_add_date = models.datetimefield(auto_now_add=true) firm_last_edited = models.datetimefield(auto_now=true) status_firm = models.charfield(max_length=40, default='active') status_site = models.charfield(max_length=40, default='pending') slug = models.slugfield(max_length=140, unique=true)
my form:
class addbusinessform(): firma_name = forms.charfield(max_length=80, required=true, help_text='required.') firm_adress = forms.charfield(max_length=150, required=true, help_text='required.') firm_city = forms.charfield(max_length=50, required=true, help_text='required.') firm_desc = forms.charfield(widget=forms.textarea, required=true, help_text='required. company') firm_email = forms.emailfield(max_length=80, required=true, help_text='required. please write valid email') firm_phone = forms.charfield(max_length=150, required=true, help_text='required.') firm_website = forms.charfield(max_length=80, required=true, help_text='required.') class meta: model = firma fields = ('firm_name', 'firm_adres','firm_city', 'firm_desc','firm_email','firm_telefon','firm_website')
my url :
url(r'add-business/$',views.add_business, name='add_business'),
my view:
def add_business(request): if request.method == 'post': form = addbusinessform(request.post) if form.is_valid(): form.save() return redirect('memberships/dashboard') else: form = addbusinessform() return render(request, 'directory/add-business.html', {'form': form})
your model form should subclass of forms.modelform
:
class addbusinessform(forms.modelform):
Comments
Post a Comment