skip to Main Content

I’ve tried to fix this issue with chat GPT for a while now, but it says that everything okay, but it clearly ain’t. For now I;m trying to just run the e-mail field before doing the rest. Here are my files:
forms.py:

from django import forms


class SignupForm(forms.Form):
    email = forms.EmailField()
    password = forms.CharField(widget=forms.PasswordInput())
    firstname = forms.CharField(widget=forms.TextInput())
    lastname = forms.CharField(widget=forms.TextInput())
    isOwner = forms.BooleanField()

the form:

<form method="post" action="{% url 'signup' %}" class="registerForm">
        {% csrf_token %}
        {{ form.as_p }}
        <div class="header">Registration</div>

        <div class="loginText">E-mail:</div>
        <div class="loginInformation">
            {{ form.email.label_tag }}
            {{ form.email }}
        </div>

    </form>

and my controller:

@api_view(('GET', 'POST',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def signup(request):
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            account = accountService.signup(
                request.POST["email"],
                request.POST["password"],
                request.POST["firstName"],
                request.POST["lastName"],
                request.POST["isOwner"]
            )
            if account:
                return Response({'account': account}, template_name="index.html")
    else:
        form = SignupForm()
    return render(request, "signup.html", {"form": form})

Resolution for anyone stupid like me:

I’ve been using 2 seperate functions, one to access the registration page:

def getSignupForm(request):
    return render(request, "signup.html")

and second one to create the form signup(request) from above.

I though Django will be able to run this funtion with this part of the form action="{% url 'signup' %}", but it doesn’t… I just had to change the onlick action on my button to run the signup function instead of getSignupForm. FML

2

Answers


  1. Chosen as BEST ANSWER

    Resolution for anyone stupid like me:

    I've been using 2 seperate functions, one to access the registration page:

    def getSignupForm(request):
        return render(request, "signup.html")
    

    and second one to create the form signup(request) from above.

    I though Django will be able to run this funtion with this part of the form action="{% url 'signup' %}", but it doesn't... I just had to change the onlick action on my button to run the signup function instead of getSignupForm. FML


  2. You didn’t write context data for render

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search