Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Request.POST或Request.POST.get都不在views.py中提供值_Python_Django_Python 3.x_Django Views - Fatal编程技术网

Python Request.POST或Request.POST.get都不在views.py中提供值

Python Request.POST或Request.POST.get都不在views.py中提供值,python,django,python-3.x,django-views,Python,Django,Python 3.x,Django Views,我在解决方案中没有使用表单,只是尝试从request.POST获取值,以便将其保存在Views.py中的数据库中 它以前工作过,但奇怪的是,当我打印请求对象的键、值对时,它有时显示值,有时没有值 HTML: <form id="modify" class="form-horizontal" action="{% url 'modify' customer.customerid %}" method="POST"> {

我在解决方案中没有使用表单,只是尝试从request.POST获取值,以便将其保存在Views.py中的数据库中

它以前工作过,但奇怪的是,当我打印请求对象的键、值对时,它有时显示值,有时没有值

HTML:

                <form id="modify" class="form-horizontal" action="{% url 'modify' customer.customerid %}" method="POST">
                  {% csrf_token %}
                <fieldset class="scheduler-border">
                  <legend  class="scheduler-border">{{ customer.customername }}</legend>
                    <div class="form-group">
                        <span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-building bigicon"></i><label for="txtCustomerName">Customer Name</label></span>
                        <div class="col-md-11">
                            <input type="text" name="txtCustomerName" id ="txtCustomerName" class="form-control"  placeholder="Customer Name" value="{{ customer.customername }}" disabled="True">
                        </div>
                    </div>
                    <div class="form-group">
                        <span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-building bigicon"></i><label for="txtCustShortName">Customer Short Name</label></span>
                        <div class="col-md-11">
                            <input type="text" name="txtCustShortName" id="txtCustShortName" class="form-control" placeholder="Customer Short Name" value="{{ customer.customershortname }}" disabled="True">
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-md-5 col-md-offset-2 text-left">
                          <span class="col-md-1"><i class="fa fa-user bigicon"></i><label for="txtContactFirstName">Contact Person First Name</label></span>
                          <div class="col-md-12">
                            <input type="text" name="txtContactFirstName" id="txtContactFirstName" placeholder="Contact Person First Name" class="form-control" value="{{ contact.firstname }}" disabled="True">
                          </div>
                        </div>
                        <div class="form-group col-md-1 text-left">
                        </div>
                        <div class="form-group col-md-5 col-md-offset-2 text-left">
                          <span class="col-md-1"><i class="fa fa-user bigicon"></i><label for="txtContactLastName">Contact Person Last Name</label></span>
                          <div class="col-md-12">
                            <input type="text" name="txtContactLastName" id="txtContactLastName" placeholder="Contact Person Last Name" class="form-control" value="{{ contact.lastname }}" disabled="True">
                          </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-envelope bigicon"></i><label for="txtCustomerEmail">Email</label></span>
                        <div class="col-md-11">
                            <input type="text" name="txtCustomerEmail" id="txtCustomerEmail" placeholder="Contact Email Address" class="form-control" value="{{ contact.contactemail }}" disabled="True">
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-md-5 col-md-offset-2 text-left">
                          <span class="col-md-1"><i class="fa fa-flag-checkered bigicon"></i><label for="selCustCountry">Country</label></span>
                          <div class="col-md-12">
                            <select name="selCustCountry" id="selCustCountry" class="form-control" disabled="True">
                              {% for c in country %}
                              <option value= "{{ c.countryshortname }}" {% if c.countryshortname in customer.country %}selected{% endif %}>{{ c.countryname }}</option>
                              {% endfor %}
                            </select>
                          </div>
                        </div>
                        <div class="form-group col-md-1 text-left">
                        </div>
                        <div class="form-group col-md-5 col-md-offset-2 text-left">
                          <span class="col-md-1"><i class="fa fa-flag bigicon"></i><label for="selCustState">State</label></span>
                          <div class="col-md-12">
                            <select name="selCustState" id="selCustState" class="form-control" disabled="True">
                              {% for l in location %}
                              <option value= "{{ l.locationshortname }}" {% if l.locationshortname in customer.state %}selected{% endif %}>{{ l.locationname }}</option>
                                {% endfor %}
                            </select>
                          </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <span class="col-md-1 col-md-offset-2 text-center"><i class="fa fa-globe bigicon"></i><label for="selCustTimeZone">Time Zone</label></span>
                        <div class="col-md-11">
                          <select name="selCustTimeZone" id="selCustTimeZone" class="form-control" disabled="True">
                            {% for l in location %}
                            <option value= "{{ l.timezone }}" {% if l.timezone in customer.timezone %}selected{% endif %}>{{ l.timezone }}</option>
                              {% endfor %}
                          </select>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-md-5 col-md-offset-2 text-left">
                          <span class="col-md-1"><i class="fa fa-calendar bigicon"></i><label for="dtMSAStartDate">MSA Start Date</label></span>
                          <div class="col-md-12">
                              <input type="date" name="dtMSAStartDate" id="dtMSAStartDate" class="form-control" value= "{{ customer.msastartdate|date:'Y-m-d' }}" disabled="True">
                          </div>
                        </div>
                        <div class="form-group col-md-1 text-left">
                        </div>
                        <div class="form-group col-md-5 col-md-offset-2 text-left">
                          <span class="col-md-1"><i class="fa fa-calendar bigicon"></i><label for="dtMSAEndDate">MSA End Date</label></span>
                          <div class="col-md-12">
                              <input type="date" name="dtMSAEndDate" id="dtMSAEndDate" class="form-control" value="{{ customer.msaenddate|date:'Y-m-d' }}" disabled="True">
                          </div>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-md-5 col-md-offset-2 text-left">
                          <span class="col-md-1"><i class="fa fa-check-square bigicon"></i><label class="form-check-label" for="chkExternalCustomer">External Customer</label>
                            <span class="custom-control-indicator">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp;</span>
                            <input type="checkbox" name="chkExternalCustomer" id="chkExternalCustomer" class="form-check-input lg" checked="{{ customer.externalcustomer }}" disabled="True">
                            </span>
                          </div>
                        <div class="form-group col-md-1 text-left">
                        </div>
                        <div class="form-group col-md-5 col-md-offset-2 text-left">
                          <span class="col-md-1"><i class="fa fa-check-square bigicon"></i><label class="form-check-label" for="chkAllDSReq">All Data Source</label>
                            <span class="custom-control-indicator">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp;</span>
                            <input type="checkbox" name="chkAllDSReq" id="chkAllDSReq" class="form-check-input lg" checked="{{ customer.alldatasourcerequired }}" disabled="True">
                            </span>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-8">
                            <span>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp;</span>
                        </div>
                    </div>

                    <div class="form-row">
                      <div class="form-group col-md-1 text-center">
                        <a href="javascript:{document.getElementById('modify').submit()}"><button class="btn btn-primary" type="button" name="btnSave" id="btnSave">
                          <span class="fa fa-save smallicon">&nbsp;</span>Save</button></a>
                      </div>
                      <div class="form-group col-md-2 text-center">
                        <button class="btn btn-primary" type="button" name="btnCancel" id="btnCancel">
                          <span><i class="fa fa-undo smallicon"></i>&nbsp;</span>Cancel</button>
                          <button class="btn btn-primary" type="button" name="btnEdit" id="btnEdit">
                            <span><i class="fa fa-edit smallicon"></i>&nbsp;</span>Edit Customer Details</button>
                        </div>
                        <div class="form-group col-md-2 text-center">
                        </div>
                        <div class="form-group col-md-2 text-center">
                        </div
                        <div class="form-group col-md-2 text-center">
                          <a href="javascript:{document.getElementById('edit').submit()}"><button class="btn btn-primary" type="button" name="btnView" id="btnView">
                            <span><i class="fa fa-eye smallicon"></i>&nbsp;</span>View Service Details</button></a>
                        </div>
                        <div class="form-group col-md-1 text-center">
                        </div>
                    </div>
                </fieldset>
            </form>
Model.py

class Customer(models.Model):
     customerid = models.AutoField(db_column='CustomerID', primary_key=True)  # Field name made lowercase.
     customername = models.CharField(db_column='CustomerName', max_length=50)  # Field name made lowercase.
     customershortname = models.CharField(db_column='CustomerShortName', max_length=50)  # Field name made lowercase.
     msastartdate = models.DateField(db_column='MSAStartDate')  # Field name made lowercase.
     msaenddate = models.DateField(db_column='MSAEndDate')  # Field name made lowercase.
     externalcustomer = models.BooleanField(db_column='ExternalCustomer')  # Field name made lowercase.
     state = models.CharField(db_column='State', max_length=50)  # Field name made lowercase.
     country = models.CharField(db_column='Country', max_length=50)  # Field name made lowercase.
     alldatasourcerequired = models.BooleanField(db_column='AllDataSourceRequired')  # Field name made lowercase.
     timezone = models.CharField(db_column='TimeZone', max_length=50)  # Field name made lowercase.
     lastmodifiedutc = models.DateTimeField(db_column='LastModifiedUTC')  # Field name made lowercase.
     lastmodifiedby = models.CharField(db_column='LastModifiedBy', max_length=50)  # Field name made lowercase.
     active = models.BooleanField(db_column='Active')  # Field name made lowercase.

    class Meta:
         managed = False
         db_table = 'Customer'
使用呈现表单的视图进行更新:

def detail(request, customer_customerid):
    customer = get_object_or_404(Customer, pk=customer_customerid)
    contact =  Contact.objects.get(reftable='Customer', 
    refid=customer_customerid)
    country =  Country.objects.all()
    location = LocationTimezoneMapping.objects.all()
    context = {'customer':customer,'contact':contact, 'country': country, 'location':location}
    return render(request, 'customers/detail.html', context)

我需要更新html表单中的URL,方法是在URL后面加上“modify”,这样在单击Save按钮后,登录URL和URL就会有所不同

这是必要的,因为“我的视图”和“编辑”页面位于同一html上

html中的jquery

      $("#btnSave").click(function(){

        $(location).attr("href").append("modify")
        $("#frmDetails").submit();
     });
URL.py

path('modify/<int:customer_customerid>/', views.modify, name='modify'),
path('modify/',views.modify,name='modify'),

您可以共享用于点击视图的确切url吗?url:path('modify/',views.modify,name='modify'),它实际上会点击视图定义,因为我可以从def modify内部打印(“调试”)。如何在url中传递此“txtCustShortName”?希望是这样-/modify/2?txtCustShortName='hi'No..form方法是POST而不是GET。因此,这些值不会作为URL中的查询字符串传递。您可以显示呈现表单的视图吗?
path('modify/<int:customer_customerid>/', views.modify, name='modify'),