user8887187
user8887187

Reputation:

Why isn't my page redirecting after I submit the form or refresh the page in Django?

I am working on a Django application but I am not getting the desired results. The create_job page is not rendering after I submit the the form or refresh the entire page.

This is the create_job_page view

def create_job_page(request):
    current_customer = request.user.customer
    
    if not current_customer.stripe_payment_method_id:
        return redirect(reverse('customer:payment_method'))
    # return render(request, 'customer/create_job.html')
    # Filtering
    create_job = Job.objects.filter(customer=current_customer, status=Job.CREATING_STATUS).last()
    
    step1_form = forms.JobCreateStep1Form(instance=create_job)
    
    if request.method == 'POST':
        if request.POST.get('step') == '1': #If it's form one
            step1_form = forms.JobCreateStep1Form(request.POST, request.FILES)
            if step1_form.is_valid():
                creating_job = step1_form.save(commit=False)
                # Adding current customer to the form
                creating_job.customer = current_customer
                creating_job.save()
                return redirect(reverse('customer:create_job'))
            
    
    return render(request, 'customer/create_job.html', {
        "step1_form": step1_form
    })

This is the HTML code


<b>Create a Job</b>
            <div class="tab-content" id="pills-Content">
                <div class="tab-pane fade" id="pills-info" role="tabpanel" aria-labelledby="pills-info-tab">
                    <h1>Item Info</h1>
                    <form method="POST" enctype="multipart/form-data">
                        <b class="text-secondary">Item Information</b></br>
                        <div class="card bg-white mt-2 mb-5">
                            <div class="card-body">
                                {% csrf_token %}
                                {% bootstrap_form step1_form %}
                            </div>
                        </div>
                        <input type="hidden" name="step" value="1">
                        <button class="btn btn-primary" type="submit">Save &    Continue</button>
                    </form>
                </div>

Upvotes: 0

Views: 169

Answers (1)

Beikeni
Beikeni

Reputation: 900

In django i never use reverse, i generally just write redirect('app:url_name')

Upvotes: 0

Related Questions