Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django signup form doesn't submit data or save in database or valid and invalid errors working

$ I was trying to submit this following codes , it never submit or saved in database or give any reaction , even the warnings or (valid and invalid of bootsrap5.2 in not working) , i need support, thank you alot

$ this is code in the (views.py),

from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import login as signin
from django.contrib.auth import authenticate
# This can replace the 3 uppers
from .forms import SignUpForm
def signup(request):  
form = SignUpForm()
if request.method == 'POST' and 'btnsignup2' in request.POST:
    form = SignUpForm(request.POST)
    if form.is_valid(): 
        user = form.save()
        signin(request, user)
        return redirect('index')
    else:
        form = SignUpForm()

context = {                
    'basic': 
        {'main': 'Project',
            },
    'form': form
}
return render(request, 'accounts/signup-dj.html', context)

$ this is code in the (forms.py)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import login as signin
from django.contrib.auth import authenticate
from django.contrib.auth.models import User

class SignUpForm(UserCreationForm):
email = forms.EmailField(max_length=250, required=True, widget=forms.EmailInput())
class Meta:
    model = User 
    fields = ['first_name', 'last_name', 'email', 'username', 'password1', 'password2']

$ this is (urls.py)

from django.urls import path
from . import views

urlpatterns = [
path('login', views.login, name="login"),
path('signout', views.signout, name="signout"),
path('signup', views.signup, name="signup"),
]

$ this is code in the (HTML)

{% extends 'base.html' %}
{% load static %} 
{% block title %}Sign Up{% endblock %}<!-- | Page-title-->
{% block content %}
<div class="signup-form">
<div class="container-signup w-50">
    <h1>Sign Up</h1>
    <br>
    {% include 'parts/alerts.html' %}
    <form class="row g-3" metho="POST" action="">
        {% csrf_token %} 
        {% include 'includes/form.html' %}


        <button type="submit" name="btnsignup2" class="btn main-btn w-100 rounded-pill">
            Create New User</button>
        <p class="mt-3">
            You Already Have Account at {{basic.main}} ? <a href="{% url 'login'
          %}">Login</a>
        </p>
    </form>
    </div>
    </div>
{% endblock %} 

>Solution :

Just looking at the HTML I can see that here:

<form class="row g-3" metho="POST" action="">

you have a typo in metho="POST", it should be method="POST", and assign the url of the endpoint to action, like action="/signup".

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading