In my registration page, I am able to input a file other than an image for example -.txt or .py then save it. Even though my model is an Imagefield it allows files other than images. I have other models with imagefield in them but they are working fine. When I try to save a txt or py file there it raises an error. But in my registration page it directly saves it. I have also added validators still does not work. Note that when I try to edit user from admin page there it raises an error.
models.py :
from django.contrib.auth.models import User
from django.core.validators import validate_image_file_extension
from django.db import models
from django.utils import timezone
from multiselectfield import MultiSelectField
# Create your models here.
class UserProfileInfo(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, help_text=False)
profile_pic = models.ImageField(upload_to="profile_pic/",validators=[validate_image_file_extension], null=True , blank=True)
def __str__(self):
return self.user.username
views.py
def register(request):
accounts = User.objects.all()
if request.method == "POST":
user_form = UserForm(data=request.POST)
profile_form = UserProfileInfoForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.is_active = False
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'profile_pic' in request.FILES:
profile.profile_pic = request.FILES['profile_pic']
profile.save()
messages.success(request, 'Your account has been created Sucessfully!!!!')
messages.success(request, 'You can use your account after it has been approved by the admins.')
return redirect("/")
else:
messages.error(request, user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileInfoForm()
return render(request, 'MyTestApp/registration.html', {
'user_form': user_form,
'profile_form': profile_form,
"accounts": accounts}
)
and template :
<div class="jumbotron ">
<form method="post" enctype='multipart/form-data' autocomplete="off">
{%csrf_token%}
<div class="form-group row">
{% if user.is_authenticated %}
<h2>LOGOUT TO CREATE A NEW ACCOUNT </h2>
{% else %}
<h2>Please Register Here: </h2>
</div>
<br>
<div class="form-group row">
<label >{{ user_form.username.label }}</label>
{{ user_form.username }}
{{user_form.username.errors}}
</div>
<div class="form-group row">
<label>{{ user_form.password.label }}</label>
{{ user_form.password }}
{{user_form.password.errors}}
</div>
<div class="form-group row">
<label >{{ user_form.email.label }}</label>
{{ user_form.email }}
{{user_form.email.errors}}
</div>
<div class="form-group row">
<label>Profile Picture: </label>
{{ profile_form.profile_pic }}
{{ profile_form.profile_pic.errors}}
</div>
<br>
<div class="form-group row">
<input type="submit" name="userregister" value="Register" class="btn btn-dark">
</div>
</form>
</div
Related
Good day,
I am making a Django application,
I want to call my data that the user signs up with and to display the information they submitted as:
Name
Email
Then I want to be able to change that data and then I want to save it, and reload back into the dashboard, but when I am updating my 'update_profile.html' the info is not updating, I can; add form data and change it
What am I doing wrong?
My code below:
views.py
from django.shortcuts import render, redirect, HttpResponse
from django.contrib import messages, auth
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from contacts.models import Contact
def register(request):
if request.method == 'POST':
# Get form values
first_name = request.POST['first_name']
last_name = request.POST['last_name']
username = request.POST['username']
email = request.POST['email']
password = request.POST['password']
password2 = request.POST['password2']
# Check if passwords match
if password == password2:
# Check username
if User.objects.filter(username=username).exists():
messages.error(request, 'That username is taken')
return redirect('register')
else:
if User.objects.filter(email=email).exists():
messages.error(request, 'That email is being used')
return redirect('register')
else:
# Looks good
user = User.objects.create_user(
username=username, password=password, email=email, first_name=first_name, last_name=last_name) # noqa
# Login after register
auth.login(request, user)
messages.success(request, 'You are now logged in')
return redirect('index')
# user.save()
# messages.success(
# request, 'You are now registered and can log in')
# return redirect('login')
else:
messages.error(request, 'Passwords do not match')
return redirect('register')
else:
return render(request, 'accounts/register.html')
def login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
messages.success(request, 'You are now logged in')
return redirect('dashboard')
else:
messages.error(request, 'Invalid credentials')
return redirect('login')
else:
return render(request, 'accounts/login.html')
def logout(request):
if request.method == 'POST':
auth.logout(request)
messages.success(request, 'You are now logged out')
return redirect('index')
#login_required(login_url='login')
def dashboard(request):
user_contacts = Contact.objects.order_by(
'-contact_date').filter(user_id=request.user.id)
context = {
'contacts': user_contacts
}
return render(request, 'accounts/dashboard.html', context)
#login_required(login_url='login')
def edit_profile(request, pk):
user = User.objects.get(id=pk)
if request.method == 'POST':
...
user.name = request.GET['name']
user.email_address = request.GET['email_address']
user.save()
return redirect('dashboard')
context = {
'user': user
}
return render(request, 'accounts/dashboard.html', context)
#login_required(login_url='login')
def delete_profile(request, pk):
user = User.objects.get(id=pk)
if request.method == 'POST':
...
user.name = request.GET['name']
user.email_address = request.GET['email_address']
user.delete()
return redirect('index')
context = {
'user': user
}
return render(request, 'index.html', context)
Then my urls
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('register', views.register, name='register'),
path('login', views.login, name='login'),
path('logout', views.logout, name='logout'),
path('dashboard', views.dashboard, name='dashboard'),
path('edit_profile/<int:pk>/', views.edit_profile, name='edit_profile'),
]
Lastly My edit_profile.html
{% extends 'base.html' %}
{% block title %} | Edit Profile {% endblock %}
{% block content %}
<section id="showcase-inner" class="py-5 text-white">
<div class="container">
<div class="row text-center">
<div class="col-md-12">
<h1 class="display-4">User Dashboard</h1>
<p class="lead">Manage your BT Real Estate account</p>
</div>
</div>
</div>
</section>
<!-- Breadcrumb -->
<section id="bc" class="mt-3">
<div class="container">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="{% url 'index' %}">
<i class="fas fa-home"></i> Home</a>
</li>
<li class="breadcrumb-item active"> Dashboard</li>
</ol>
</nav>
</div>
</section>
{% comment %} Alerts {% endcomment %}
{% include 'partials/__alerts.html' %}
<section id="dashboard" class="py-4">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Welcome {{ user.first_name }}
<a class="btn btn-info" href="{% url 'dashboard' %}">
Save Profile
</a>
<a class="btn btn-da nger" href="{% url 'dashboard' %}">
Del;ete Profile
</a>
</h2>
<h3>Account Details: </h3>
<form action="{% url 'contact' %}" method="POST">
{% csrf_token %}
{% if user.is_authenticated %}
<input type="hidden" name="user_id" value="{{ user.id }}">
{% else %}
<input type="hidden" name="user_id" value="0">
{% endif %}
<input type="hidden" name="realtor_email" value="{{ listing.realtor.email }}">
<input type="hidden" name="listing_id" value="{{ listing.id }}">
<div class="form-group">
<label for="property_name" class="col-form-label">Property:</label>
<input type="text" name="listing" class="form-control" value="{{ listing.title }}" >
</div>
<div class="form-group">
<label for="name" class="col-form-label">Name:</label>
<input type="text" name="name" class="form-control" {% if user.is_authenticated %} value="{{ user.first_name }} {{ user.last_name }}" {% endif %} required>
</div>
<div class="form-group">
<label for="email" class="col-form-label">Email:</label>
<input type="email" name="email" class="form-control" {% if user.is_authenticated %} value="{{ user.email }}" {% endif %} required>
</div>
<div class="form-group">
<label for="phone" class="col-form-label">Phone:</label>
<input type="phone" name="phone" class="form-control" {% if user.is_authenticated %} value="{{ user.phone }}" {% endif %} >
</div>
<input type="submit" value="Send" class="btn btn-block btn-secondary">
</form>
</div>
</div>
</div>
</section>
{% endblock %}
PLEASE HELP!
###I have model named Publisher in models.py file.###
###And based on this model, a modelForm has made, called "RegistrationForm".###
###Which renders form on registration.html template.###
<br /> <br />**This is code of registration.html**
<pre><code>
```
<body>
<div class="container">
{% load my_filters %}
<div class="row">
<div class="col-md-6 offset-md-3">
{% if registered %}
<h1>Thank you for registering!</h1>
{% else %}
<h1>Register Here</h1>
<h3>Just fill out the form.</h3>
<form enctype="multipart/form-data" method="POST">
{% csrf_token %}
{{ reg_form.non_field_errors }}
<div class="fieldWrapper">
<div class="form-group">
{{ reg_form.name.errors }}
<label for="{{ reg_form.name.id_for_label }}" >Name:</label>
{{ reg_form.name|addclass:'form-control' }}
</div>
</div>
<div class="fieldWrapper">
<div class="form-group">
{{ reg_form.email.errors }}
<label for="{{ reg_form.email.id_for_label }}">Email:</label>
{{ reg_form.email|addclass:'form-control' }}
</div>
</div>
<div class="fieldWrapper">
<div class="form-group">
{{ reg_form.contact.errors }}
<label for="{{ reg_form.contact.id_for_label }}">Contact:</label>
{{ reg_form.contact|addclass:'form-control' }}
</div>
</div>
<div class="fieldWrapper">
<div class="form-group">
{{ reg_form.password.errors }}
<label for="{{ reg_form.password.id_for_label }}">Password:
</label>
{{ reg_form.password|addclass:'form-control' }}
</div>
</div>
<div class="fieldWrapper">
<div class="form-group">
{{ reg_form.confirm_password.errors }}
<label for="{{ reg_form.confirm_password.id_for_label }}">Confirm
Password:</label>
{{ reg_form.confirm_password|addclass:'form-control' }}
</div>
</div>
<input type="submit" name="" value="Register">
</form>
{% endif %}
</div>
</div>
</div>
</body>
```
</code></pre>
### I am NOT using crispy forms just manually rendering Django forms and using manual template tag to add classes to fields.
**This is the template tag in used to add classes to form fields**
<code><pre>
```
#register.filter(name='addclass')
def addclass(value, arg):
return value.as_widget(attrs={'class': arg})
```
</code></pre>
**This is the model in models.py**
<code><pre>
```
class Publisher(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField('Name', max_length=50)
email = models.EmailField('Email', unique=True)
password = models.CharField('Password', max_length=50)
contact = models.CharField('Contact #', max_length=16, unique=True, validators=[
RegexValidator(
regex=r'^\+?1?\d{9,15}$',
message="Phone number must be entered in the format '+123456789'. Up to 15 digits allowed."
),
],)
def __str__(self):
return self.name
```
</code></pre>
**This is the form in forms.py file**
<code><pre>
```
class RegistrationForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
confirm_password = forms.CharField(widget=forms.PasswordInput())
class Meta():
model = Publisher
fields = ('name','email','contact','password')
def clean(self):
cleaned_data = super(RegistrationForm, self).clean()
password = cleaned_data.get("password")
confirm_password = cleaned_data.get("confirm_password")
if password != confirm_password:
raise forms.ValidationError(
"password and confirm_password does not match"
)
```
</code></pre>
**This is the view in views.py file**
<code><pre>
```
def registration(request):
registered = False
if request.method == 'POST':
reg_form = RegistrationForm(data=request.POST)
if reg_form.is_valid():
user = reg_form.save()
user.save()
registered = True
else:
#Now issue is this printing statement working fine and printing errors on console.But
#errors are not showing on template.
print(reg_form.errors)
else:
reg_form = RegistrationForm()
return render(request, 'seller/registration.html',
{'reg_form': RegistrationForm,
'registered': registered
})
```
</code></pre>
I have seen all the stack overflow and tried many thing but none of them help me TO GET MY ERRORS ON FORM TEMPLATE (Though errors like password doesn't match and contact number error etc are getting printed on django console as defined in else statement of views.py file).
After filling form with wrong data pressing "submit" button it refreshes the form rather showing errors. And after filling form with with right data user gets registered (It shows "Thank you for registering" as defined in template). I know there must be silly thing I am doing or missing. Kindly let me know.
I noticed that when I upload a profile picture the picture is not being saved in my media directory.
I have manually created the folder and referenced it in settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls.py:
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
models.py:
class User(AbstractUser):
is_student = models.BooleanField(default=False)
is_teacher = models.BooleanField(default=False)
...
class Mentor(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE,primary_key=True)
linkedin = models.URLField(max_length=200,null=True,blank=True)
photo = models.ImageField(null=True, blank=True, upload_to='media')
forms.py
#basic form
class UserForm(forms.ModelForm):
class Meta:
model = User
fields = ('first_name','last_name','email')
# edit mentor profile
class MentorProfileForm(forms.ModelForm):
class Meta:
model = Mentor
fields = ('photo',)
and views.py:
def edit_user(request):
user = request.user
# form = MentorProfileForm(instance=user)
if request.method == 'POST':
form = UserForm(request.POST, request.FILES, instance=user)
mentorform = MentorProfileForm(request.POST, request.FILES, instance=user)
if form.is_valid() and mentorform.is_valid():
form.save()
mentorform.save()
messages.success(request, ('Your profile was successfully updated!'))
return HttpResponseRedirect('%s' % (reverse('teachers:edit_user')))
else:
messages.error(request, ('Please correct the error below.'))
else:
form = UserForm(request.POST, instance=user)
mentorform = MentorProfileForm(request.POST, request.FILES, instance=user)
return render(request, 'classroom/teachers/app-instructor-profile.html', {'form': form,
'mentor_form': mentorform})
EDIT
As requested here is the html template I am using to upload the picture and other profile info. I am convinced that the problem is with my html. I'm not sure what else I could be doing wrong
<form id="edit-mentor-profile" class="form-horizontal" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-group">
<label for="photo" class="col-sm-2 control-label">Avatar</label>
<div class="col-md-6">
<div class="media v-middle">
<div class="media-left">
<div class="icon-block width-100 bg-grey-100">
<img id="image" style="width:99%;height:99%;">
</div>
</div>
<div class="media-body">
<input type="file" id="files" class="btn btn-white btn-sm paper-shadow relative" data-z="0.5" data-hover-z="1" data-animated/>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-md-2 control-label">Full Name</label>
<div class="col-md-8">
<div class="row">
<div class="col-md-6">
<div class="form-control-material">
{{ form.first_name }}
<label for="edit-mentor-profile-first_name"></label>
</div>
</div>
<div class="col-md-6">
<div class="form-control-material">
{{ form.last_name }}
<label for="edit-mentor-profile-last_name"></label>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-2 control-label">Email</label>
<div class="col-md-6">
<div class="form-control-material">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
{{ form.email }}
<label for="edit-mentor-profile-email"></label>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-6">
<div class="checkbox checkbox-success">
<input id="checkbox3" type="checkbox" checked="">
<label for="checkbox3">Subscribe to our Newsletter</label>
</div>
</div>
</div>
<div class="form-group margin-none">
<div class="col-md-offset-2 col-md-10">
<button type="submit" class="btn btn-primary paper-shadow relative" data-z="0.5" data-hover-z="1" data-animated>Save Changes</button>
</div>
</div>
</form>
As #schwobaseggl said, file should be stored in /media/media folder. But there is another problem in your code, here:
mentorform = MentorProfileForm(request.POST, request.FILES, instance=user) # <-- Here
Here it should be:
mentorform = MentorProfileForm(request.POST, request.FILES, instance=user.mentor)
Because MentorProfileForm is using Mentor model, not User model. Also you need to fix the code for handling GET request:
def edit_user(request):
user = request.user
# form = MentorProfileForm(instance=user)
if request.method == 'POST':
form = UserForm(request.POST, request.FILES, instance=user)
mentorform = MentorProfileForm(request.POST, request.FILES, instance=user.mentor)
if form.is_valid() and mentorform.is_valid():
form.save()
mentorform.save()
messages.success(request, ('Your profile was successfully updated!'))
return HttpResponseRedirect('%s' % (reverse('teachers:edit_user')))
else:
messages.error(request, ('Please correct the error below.'))
else:
form = UserForm(instance=user) # <-- Here
mentorform = MentorProfileForm(instance=user.mentor) # <-- Here
return render(request, 'classroom/teachers/app-instructor-profile.html', {'form': form,
Please use below code in your html template. Where you are using form tag.
<form enctype="multipart/form-data" method="post">
--------- --------
---------Your code-------
</form>
I am trying to use a ModelForm to save objects to the database. I have also added an ImageField. Through the admin panel, I am easily able to add objects with an image but every time I submit the ModelForm with the same image it doesn't get saved and returns an error saying "This field is required" (screenshot and code attached).
How do I fix this?
Here's a screenshot of the error:
The models file:
from django.db import models
from django.conf import settings
class Book(models.Model):
rel_user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name="Posted By")
image = models.ImageField(verbose_name="Image", upload_to="static/Books/img")
title = models.CharField(max_length=256, verbose_name="Title")
description = models.TextField(verbose_name="Description")
price = models.IntegerField(verbose_name="Price")
state = models.CharField(max_length=256, verbose_name="State")
city = models.CharField(max_length=256, verbose_name="City")
neighbourhood = models.CharField(max_length=256, verbose_name="Neighbourhood")
phone = models.IntegerField(verbose_name="Phone Number")
def __str__(self):
return self.title + f" ({self.rel_user.username})"
The forms file:
from django.forms import ModelForm
from Books.models import Book
class BookForm(ModelForm):
class Meta:
model = Book
fields = ['image', 'title', 'description', 'price', 'state', 'city', 'neighbourhood', 'phone']
The views file:
from django.shortcuts import render, redirect
from Books.forms import BookForm
from django.contrib import messages
from Books.models import Book
def sell(request):
if request.method == "GET":
form = BookForm()
else:
form = BookForm(request.POST)
form.instance.rel_user = request.user
if form.is_valid():
form.save()
messages.success(request, "Successfully added!")
return redirect('sell')
else:
messages.error(request, "Please fill in all the fields.")
return render(request, 'Books/sell.html', {"form": form})
The HTML code:
<div class="container" style="padding: 2%">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12"></div>
<div class="col-md-4 col-sm-4 col-xs-12" style="background-color: rgba(256, 256, 256, 0.8);">
{% if messages %}
{% for message in messages %}
<div class="alert alert-primary" role="alert" style="margin-top: 2%;">
{{ message }}
</div>
{% endfor %}
{% endif %}
<form method="POST" action="{% url 'sell' %}">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Sell A Book</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Submit
</button>
</div>
</form>
</div>
<div class="col-md-4 col-sm-4 col-xs-12"></div>
</div>
</div>
from Books.forms import BookForm
from django.contrib import messages
from Books.models import Book
def sell(request):
if request.method == "GET":
form = BookForm()
else:
form = BookForm(request.POST,request.FILES)
form.instance.rel_user = request.user
if form.is_valid():
form.save()
messages.success(request, "Successfully added!")
return redirect('sell')
else:
messages.error(request, "Please fill in all the fields.")
return render(request, 'Books/sell.html', {"form": form})```
<div class="container" style="padding: 2%">
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12"></div>
<div class="col-md-4 col-sm-4 col-xs-12" style="background-color:rgba(256, 256, 256, 0.8);">
{% if messages %}
{% for message in messages %}
<div class="alert alert-primary" role="alert" style="margin-top: 2%;">
{{ message }}
</div>
{% endfor %}
{% endif %}
<form method="POST" action="{% url 'sell' %}"enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Sell A Book</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Submit
</button>
</div>
</form>
</div>
<div class="col-md-4 col-sm-4 col-xs-12"></div>
</div>
</div>
I have a SignUp form that interacts with Django's user model to create new users. If password fields match, the user is successfully created and logged in. If password fields do not match, the user is not created, so I guess validation is working. But somehow, a validation error message is not shown, the form page is just rendered again. When I go to Django's admin page, the error messages pop up there! Why is it not popping in my template?!
This is my form:
class SignUpForm(forms.ModelForm):
password = forms.CharField(max_length=20, required=True, widget=forms.TextInput(attrs={'placeholder':'Password', 'class':'form-control', 'type':'password'}),)
password2 = forms.CharField(max_length=20, required=True, widget=forms.TextInput(attrs={'placeholder':'Confirm Password', 'class':'form-control', 'type':'password'}),)
class Meta:
model = User
widgets = {'first_name': forms.TextInput(attrs={'placeholder':'First Name', 'class':'form-control'}),
'last_name': forms.TextInput(attrs={'placeholder':'Last Name', 'class':'form-control'}),
'email': forms.TextInput(attrs={'placeholder':'Email', 'class':'form-control', 'type':'email'}),
'username': forms.TextInput(attrs={'placeholder':'Username', 'class':'form-control'}),
'password': forms.TextInput(attrs={'placeholder':'Password', 'class':'form-control', 'type':'password'})
}
fields = {'first_name', 'last_name', 'email', 'username', 'password'}
def clean(self):
cleaned_data = super(SignUpForm, self).clean()
password = cleaned_data.get('password')
password2 = cleaned_data.get('password2')
if password != password2:
raise forms.ValidationError('Passwords do not match!')
And this is my view:
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user.set_password(password)
form.save()
user = authenticate(username=username, password=password)
login(request, user)
messages.add_message(request, messages.SUCCESS, 'Account created successfully!')
return HttpResponseRedirect('/')
else:
messages.add_message(request, messages.ERROR, "There's an error in the form! Please fill it again.")
return render(request, 'form/register.html', {'form': form})
else:
form = SignUpForm()
return render(request, 'form/register.html', {'form': form})
And this is my template:
<div class="login-box-body">
{% block login_form %}
<form method="POST">
{% csrf_token %}
{% if form.errors %}
{% for error in field.errors %}
<p class="login-box-msg" style="color: red;">{{ error }}</p>
{% endfor %}
{% endif %}
<div class="form-group has-feedback">
{{form.first_name}}
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
{{form.last_name}}
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
{{form.email}}
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
{{form.username}}
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
{{form.password}}
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
{{form.password2}}
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<button type="button" class="btn btn-default" onclick="window.location.href='{% url 'manager:login' %}'">Voltar</button>
</div>
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Criar Conta</button>
</div>
</div>
</form>
{% endblock login_form %}
What am I doing wrong?
Okay, I managed to work it out, at least as a temporary solution! Daniel was right, there was a typo in my template, but it was showing "_ all _" as the error message, not sure why.
Since the password fields were the only ones I was using raise forms.ValidationError function, then the error message was only to be shown in case the passwords wasn't matching.
So I just wrote the error message I wanted directly in my template! Like this:
<form method="POST">
{% csrf_token %}
{% if form.errors %}
<p class="login-box-msg" style="color: red; font-weight: bold;">Passwords do not match!</p>
{% endif %}
It doesn't work the way I wanted, but it does the job!