SIGNUP is not WORKING

I have followed the official Django Tutorials for Django Login, Logout, Signup, Password Reset and Password Change tutorial and it worked well.

I intended to change the location of template folder. In my code the template folder is in app-level.Before the change of location of template folder, I have made new sign up users and log in. They are still working well, even after the change of location of template folder.

I would like to keep the template folder in app-level(accounts). The sign up page is not signing up new users and there is no prominent error. I would seek help to fix this problem.

I have given my code below:

**views.py (app-level):**
from django.shortcuts import render
from django.contrib.auth.forms import UserCreationForm
from django.urls import reverse_lazy
from django.views.generic import CreateView

# Create your views here.
class SignUpView(CreateView):
    form_class = UserCreationForm
    success_url = reverse_lazy('login')
    template_name = "registration/signup.html"

urls.py (app-level):
from django.urls import path

from .views import SignUpView

urlpatterns = [
path(‘signup’, SignUpView.as_view(), name = ‘signup’),
]

**urls.py(project-level):**

from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import TemplateView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/', include('accounts.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('', TemplateView.as_view(template_name='home.html'), name = "home"),
]
```````````````````````````````````````````````````````````````````````````````````````````````````````````````
**signup.html:**
{% extends 'base.html' %}
{% block title %}Sign Up{% endblock %}
{% block content %}
<h2>Sign Up</h2>
{% csrf_token %}
<form method="POST">
    {% csrf_token %}
    {{ form }}
    <button type="submit">Sign Up</button>
</form>
{% endblock %}
`````````````````````````````````````````````````````````````````````````````````````````````````````````````
**settings.py:**
"""
Django settings for django_auth project.

Generated by 'django-admin startproject' using Django 5.1.4.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-rr-^5sc@6i(o3kk4_5v^$$9=t1a$tr@zc!%z$=9e3x(5%36&#x'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'django_auth.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'django_auth.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGIN_REDIRECT_URL ="home"                                                                       #New
LOGOUT_REDIRECT_URL = "home"                                                                  #New
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'           #New

base.html:

{% block title %}Django Authentication Tutorial{% endblock %} {% include 'partials/header.html' %} {% block content %} {% endblock %} {% include 'partials/footer.html' %} `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````

The only error I have encountered is Broken pipe form error. It is not taking new user sign up.
Below the screenshot of the terminal.

  1. What is your settings.py?
  2. What is the path of your base.html?

Thank you @anefta , for mentioning. I have given the settings.py and base.py file in the above code all together.

I shall remain grateful if you can help me to fix this problem.

Ok, but still you do not format properly your code, please do in the future.

Let’s see…

  1. In your signup.html template, you have two CSRF tokens. You only need one inside the form:
<form method="POST">
    {% csrf_token %}
    {{ form }}
    <button type="submit">Sign Up</button>
</form>
  1. In your app-level urls.py, the signup URL pattern is missing a trailing slash. Do this:
path('signup/', SignUpView.as_view(), name='signup'),
  1. Make sure your template directory structure is correct. Based on your settings, Django will look for templates in:
  • accounts/templates/registration/signup.html
  • templates/registration/signup.html

Is this happening every time? (The “broken pipe” message.) Or did it only happen once?

Is there any JavaScript being used on this page?

Please post the partials/header.html and partials/footer.html.

Note: When posting code or templates here, enclose the code (or template) between lines of three backtick - ` characers. This means you will have a line of ```, then the code (or templates), then another line of ```. This forces the forum software to keep your code properly formatted. (This does not mean that you create a whole line of backtick characters.) You should also do this for each file separately.

Thank you @anefta. You are truly a passionate Django Problem Solver. your suggestions are really genuine. My problem is solved.

I just need to remove the extra {% csrf_token %} outside the form tag. With or without the trailing slash, the code is really working and the issue is solved. I have checked both.

I have again tried to modify the code and I face some problem again. In this time I have tried to change the Django-HTML into HTML5 and added a basic styling by linking a CSS file for the signup.html. There is no error during the runtime but, it doesn’t accept new user through signup form. I need some help here.

Below is the code for modified signup.html fille. The rest of the code is unchanged.

**signup.html:**
{% extends 'base.html' %}
{% load static %}
{% block title %}Sign Up{% endblock %}
{% block content %}
<h2>Sign Up</h2>

<form method="POST">
    {% csrf_token %}

    <div class="ray">
        <lable>Username:</lable>
        <input type="text" placeholder="username">
    </div>
    <div class="ray">
        <label>Password:</label>
        <input type="password" placeholder="password1">
    </div>
    <div class="ray">
        <lable>Password again:</lable>
        <input type="password" placeholder="password2">
    </div>
    
    <button type="submit">Sign Up</button>
</form>
{% endblock %}

base.html:

{% block title %}Django Authentication Tutorial{% endblock %} {% include 'partials/header.html' %} {% block content %} {% endblock %} {% include 'partials/footer.html' %} ```

style.css:
.ray{
background-color: aqua;
}

There won’t be any error because you don’t have code in your template to show any errors.

If you want to render the form fields manually (instead of using {{ form }} or similar) you should see how it’s done in the Rendering fields manually section of the docs.

Also, you haven’t given the <input> fields any name attributes, so the view won’t be receiving the correct data. Look at the docs! :slight_smile:

Thank you sir @KenWhitesell for your enthusiastic efforts towards my error.

Sir, this “broken pipe” message appeared only once in the terminal. I have given the screenshot of the terminal. There is no JavaScript file in this code.

Sir, the above problem is solved. I have tried to modify the code from Django-HTML into HTML5 for signup.html file and added a simple styling. The rest of the remaining code is unchanged. There is no clear error in the code but, there is no runtime error for this code. This signup.html is not accepting new users. I can still login through my old username and password.

I have seen the official documentation for Manually render Django form. This problem is not solved completely for me.

Sir, I shall be remained grateful if you can help me to solve the problem.

Below, I have given the code:

**signup.html:**

{% extends 'base.html' %}
{% load static %}
{% block title %}Sign Up{% endblock %}
{% block content %}
<h2>Sign Up</h2>

<form method="POST">
    {% csrf_token %}

    <div class="ray">
        <lable>Username:</lable>
        <input type="text" placeholder="username">
    </div>
    <div class="ray">
        <label>Password:</label>
        <input type="password" placeholder="password1">
    </div>
    <div class="ray">
        <lable>Password again:</lable>
        <input type="password" placeholder="password2">
    </div>
    
    <button type="submit">Sign Up</button>
</form>
{% endblock %}

partials/header.html:

{% load static %}


**partials/footer.html:**

{% load static %}
<footer>
    <nav>
        <ul>
            <a href="{% url 'home'  %}">Home</a>
            <a href="{% url 'login'  %}">Log In</a>
            <a href="{% url 'signup' %}">Sign Up</a>
        </ul>
    </nav>
</footer>

base.html:

{% block title %}Django Authentication Tutorial{% endblock %} {% include 'partials/header.html' %} {% block content %} {% endblock %} {% include 'partials/footer.html' %}

**style.css:**

.ray{
    background-color: aqua;
    
}


So. here you are trying to render the UserCreationForm?

Please post your code of UserCreationForm.

You also have some typos

it shoud be : <label>Username:</label>

And as philgyford previously commented, that is why you do not see any errors:

No, that is why there are errors.

The reason they don’t see the errors is because they’re not rendering any field or non-field errors in the template.

haha, yes that is correct!

Thank you @philgyford for your keen efforts towards my Django errors.

I have used {{ form }} attribute in my code and the entire code worked well. I shall have problem to style the basic and built-in django-template in future. This is the reason I am trying to convert the entire Django-HTML into HTML5 and faced problem that it is not signing up new users.

I have studied the Manually render the form fields in Django, but it is not working for me. I have shared the code in this forum.

If you can help me to fix the problem, I shall be grateful.

signup.html:
{% extends 'base.html' %}
{% load static %}
{% block title %}Sign Up{% endblock %}
{% block content %}
<h2>Sign Up</h2>

<form method="POST">
    {% csrf_token %}

    <div class="ray">
        <lable>Username:</lable>
        <input type="text" placeholder="username">
    </div>
    <div class="ray">
        <label>Password:</label>
        <input type="password" placeholder="password1">
    </div>
    <div class="ray">
        <lable>Password again:</lable>
        <input type="password" placeholder="password2">
    </div>
    
    <button type="submit">Sign Up</button>
</form>
{% endblock %}

Follow the link I gave you: Working with forms | Django documentation | Django

. Read it and see how the form differs from yours:

{{ form.non_field_errors }}
<div class="fieldWrapper">
    {{ form.subject.errors }}
    <label for="{{ form.subject.id_for_label }}">Email subject:</label>
    {{ form.subject }}
</div>
<div class="fieldWrapper">
    {{ form.message.errors }}
    <label for="{{ form.message.id_for_label }}">Your message:</label>
    {{ form.message }}
</div>
<div class="fieldWrapper">
    {{ form.sender.errors }}
    <label for="{{ form.sender.id_for_label }}">Your email address:</label>
    {{ form.sender }}
</div>
<div class="fieldWrapper">
    {{ form.cc_myself.errors }}
    <label for="{{ form.cc_myself.id_for_label }}">CC yourself?</label>
    {{ form.cc_myself }}
</div>

Thanks @philgyford, let me try it. But still I am trying to stick in my present code.

thanks @anefta , there is no forms.py file and there is no separate code for UsercreationForm.

I have tried to change the {{ form }} in to HTML5 and added basic stylings to it. If you can provide the solution code, it will really clear the problem for me. I shall try to change the input fields and let me see the output.

Ok, so read the previous replies, test the code, paste here the results and we are here!