Forums

Not saving data

The same Aplication and Database. Makemigration and Migrate applied. On Local Server it works. On eu.pythonanywhere. com with Haggis and Python 3.11, it works. But on pythonanywhere.com with Haggis and Python 3.7, data is not saved.

The HTML is the same.

I couldn't find the error.

def feriados(request):
    folgas = FeriadosForm(request.POST or None)
    Feriados.objects.filter(data__lt = date.today()).delete()
    folgasX = Feriados.objects.all()

    v_data = ""
    if request.method == 'POST':
        v_data = datetime.strptime(request.POST['data'], '%Y-%m-%d').date()

    if folgas.is_valid() and v_data >= date.today():
        try:
            folgas.save()
        except Exception as e:
            print(f"Error saving data: {e}")
        return redirect('z_feriados')
    return render(request, "feriados.html", {'folgasX': folgasX})

What do you see in your logs and how is it failing?

There is no Log error. No error occurs in the application. It just doesn't write to the database at pythonanywhere.com. At eu.pythonanywhere.com it works normally.

If there's no error in the error.log for the web app is the any errors in the dev console in your browser?

No error appears in the console. When confirming, it continues normally and waits for the next entry, but it did not record what was typed.

Perhaps the data is invalid in some way, so it's skipping the part of the code that saves. You can add debugging prints to stderr to your code and the output will appear in your error log. Then you can use the output to see what your code is actually doing.