提交后,Django表单不重定向

时间:2018-04-14 12:22:53

标签: python html django

所以我制作了一个表单,但在我点击“提交”按钮后,它根本没有重定向。我不知道表单是否实际提交,因为在我点击提交后,网址只是添加/提交,甚至没有重定向到右页。

以下是我的观点:

def submit_company_profile(request):
  if request.session['status'] == "employer":
    form = CompanyProfileEdit(request.POST or None)
    if(request.method == 'POST' and form.is_valid()):
        company_creator_profile_id = request.session['profile_id']
        country = request.POST.get('country', False)
        province = request.POST.get('province', False)
        city = request.POST.get('city', False)
        company_name = request.POST.get('company_name', False)
        company_description = request.POST.get('company_description', False)
        company_website = request.POST.get('company_website', False)
        company_logo = request.POST.get('company_logo', False)

        query = Company.objects.filter(company_creator_profile_id=request.session['profile_id'])
        query_size = query.count()
        if query_size > 0:
            company = query[0]
            company.country = country
            company.province = province
            company.city = city
            company.company_name = company_name
            company.company_description = company_description
            company.company_website = company_website
            company.company_logo = company_logo
            company.save()
        else:
            Company.objects.create(
                company_creator_profile_id=request.session['profile_id'],
                country = country,
                province = province,
                city = city,
                company_name = company_name,
                company_description = company_description,
                company_website = company_website,
                company_logo = company_logo
            )
    return redirect(reverse('app_employer:company_profile'))

这是我的HTML

<form method="POST" action="{% url 'app-employer:submit-company-profile' %}">
                    {% csrf_token %}
                    {% for field in company_form %}
                    <div class="form-group">
          <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        {{field}}
                    </div>
                    {% endfor %}
        <div class="upload">
          <p><strong>Upload your company logo</strong></p>
          <div class="row">
            <div class="col-sm-4">
              <button class="btn btn-block btn-default">Choose File</button>
            </div>
            <div class="col-sm-4">
              <div class="text-file-name">
                <p style="color:#999">No file chosen</p>
              </div>
          </div>
        </div>
      </div>

        <div class="btn-padding-form">
                        <input id="submit" type="submit" class="btn btn-info btn-md btn-block" value="Submit">
        </div>
      </form>

上传徽标按钮尚无法使用。所以我要在不上传徽标的情况下提交表格。

0 个答案:

没有答案