python - The submitted form is not saved in sql - dJango -


i have searched posts issue still not find solution. after clicking "submit", page redirect page. sql database doesn't show submitted information.

thanks in advance suggestion.

views.py

@csrf_exempt def input(request):     if request.method == 'post':         form = inputform(request.post or none, request.files or none)         if form.is_valid():             company = form.cleaned_data['company']             region = form.cleaned_data['region']             uom= form.cleaned_data['uom']             start_date= form.cleaned_data['start_date']             end_date= form.cleaned_data['end_date']             add_input=input.objects.create(company=company,region=region,uom=uom,start_date=start_date,end_date=end_date)             add_input.save()             return redirect('resut')         else:             print(form.errors)     else:         form = inputform(initial={'company':'coco','uom':'m$'},instance=input)         return render_to_response('inputform.html',{'form': form}) 

models.py

class input(models.model):     company=models.charfield(max_length=100)     region=models.charfield(max_length=100)     uom=models.charfield(max_length=100)     start_date=models.datefield(auto_now=false, auto_now_add=false)     end_date=models.datefield(auto_now=false, auto_now_add=false) 

forms.py

class inputform(forms.modelform):     company=forms.charfield(widget=forms.textinput, label="company",error_messages={'required': 'please enter name'},required=true)     regionlist = forms.modelchoicefield(queryset=dupont.objects.values('region').distinct())     uom=forms.charfield(required=true)     start_date=forms.datefield(widget=dateinput(),required=true)     end_date = forms.datefield(widget=dateinput(),required=true)     error_css_class='error'     required_css_class = 'required'      class meta:         model = input         fields = ('company', 'region','uom','start_date','end_date')         widgets = {             'start_date': forms.dateinput(attrs={'class':'datepicker'}),             'end_date': forms.dateinput(attrs={'class':'datepicker'}),         } 

html snippet

<form action="{% url 'result' %}" method="post">{% csrf_token %}          <!--company-->          <div class="field">             <p>company:<input type="text" name="company" value="{{company}}"/>         </div>           <!--region-->         <div class="field" >             <label> select region:             {{ form.regionlist }}                 {% region in form.regionlist.choices %}                      <option value="{{ val }}" {% ifequal data.val val %}selected {% endifequal %}></option>                 {% endfor %}             </label>         </div>          <!--uome-->         <div class="field">             <p>unit of measure:<input type="text" name="uom" value="{{uom}}"/>         </div>           <!--start date-->         <label for="startdate">start month:</label>         <input name="start_date" id="startdate" class="date-picker"/>          <!--end date-->         <label for="enddate">end month:</label>         <input name="end_date" id="enddate" class="date-picker" />           <!--submit-->         <div class="fieldwrapper">         <p><input type="submit" value="submit" /></p></div>  {% if form.errors %}     {% field in form %}         {% error in field.errors %}             <div class="alert alert-error">                 <strong>{{ error|escape }}</strong>             </div>         {% endfor %}     {% endfor %}     {% error in form.non_field_errors %}         <div class="alert alert-error">             <strong>{{ error|escape }}</strong>         </div>     {% endfor %} {% endif %}    </form> 

no, action point view, instead of input view. don't paste view because issue form's data doesn't saved successfully.

well thats problem, when submit form goes specified action. if snippet inputform.html suspect need delete action form.

<form method="post"> 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -