[Answered ]-Django form not sending data to admin

1👍

Try this view:

from django.contrib.auth.decorators import login_required

from django.shortcuts import redirect,render

@login_required(login_url="accounts/login")
def Book(request):

    if request.method=="POST":
        book_form = BookForm(request.POST)

        if book_form.is_valid():
            book_form.save()
            return redirect("some_success_page")

        else:       
            return redirect("some_error_page")
    else:
        book_form = BookForm()
    return render(
        request,
        "book.html",
        {
            "book_form": book_form,
        }
    )

In settings.py

LOGIN_URL="accounts/login"

Leave a comment