I need help to solve this [closed]

I’m encountering an issue with one of my Django views, and I’m hoping someone can help me troubleshoot it.

When I try to access the URL: https://tout-talent.com/forfait/, the browser or site displays a different page with the message:

{"success": false, "message": "Invalid request method"}

However, on my server and in the debug.log file, I see the following log entry:

"GET /forfait/ HTTP/1.1" 200

indicating a 200 OK HTTP status code. But the template that should normally display is not being rendered.

Here’s the code for the view :


@login_required
def subscribe(request):
    if not hasattr(request.user, 'company'):
        print("Utilisateur non connecté ou sans compagnie associée.")
        return redirect('login')  # Or show an appropriate message

    company = request.user.company
    print(f"Company: {company}")

    active_subscription = None
    try:
        active_subscription = CompanySubscription.objects.get(company=company, is_active=True)
        print(f"Active subscription found: {active_subscription}")
    except CompanySubscription.DoesNotExist:
        print("No active subscription found.")

    if request.method == 'POST':
        form = SubscriptionForm(request.POST)
        if form.is_valid():
            plan = form.cleaned_data['plan']
            print(f"Selected plan: {plan}")

            if plan.name == 'lite':
                print("Redirecting to Lite plan duration view.")
                return redirect('days_duration_for_lite_plan', plan_ref=plan.ref)
            else:
                days = plan.duration_days
                amount = plan.price_per_month if days >= 30 else plan.price_per_day * days
                print(f"Days: {days}, Amount: {amount}")

                if plan.name == 'free':
                    subscription, created = CompanySubscription.objects.get_or_create(
                        company=company,
                        defaults={
                            'plan': plan,
                            'start_date': timezone.now(),
                            'end_date': timezone.now() + timedelta(days=days),
                            'is_active': True,
                        }
                    )

                    if created:
                        print("New free subscription created.")
                    else:
                        subscription.plan = plan
                        subscription.end_date = subscription.calculate_end_date()
                        subscription.is_active = True
                        subscription.save()
                        print("Free subscription updated.")

                    return redirect('mon_forfait')  # Redirect to the user's subscription page

                # If not free, redirect to the payment page
                amount = int(amount)  # Convert amount to integer
                print(f"Redirecting to payment page with amount: {amount}")

                return redirect('payment', company_ref=company.ref, plan_ref=plan.ref, days=days, amount=amount)
        else:
            print("Form is invalid. Errors: ", form.errors)
    else:
        print("GET request received.")
        form = SubscriptionForm()

    # Retrieve subscription plans
    free_plan = SubscriptionPlan.objects.get(name='free')
    lite_plan = SubscriptionPlan.objects.get(name='lite')
    pro_plan = SubscriptionPlan.objects.get(name='pro')

    context = {
        'form': form,
        'active_subscription': active_subscription,
        'free_plan': free_plan,
        'lite_plan': lite_plan,
        'pro_plan': pro_plan,
    }

    return render(request, 'subscribe.html', context)


I’m encountering an issue with one of my Django views, and I’m hoping someone can help me troubleshoot it.

New contributor

Samuel.amou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật