Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing Django Login Form to take username over 30 characters

I'm trying to use emails for usernames, and have got it working almost perfectly. I followed these directions: http://www.micahcarrick.com/django-email-authentication.html

The problem is, my login form still is throwing an error that says the username can only be 30 characters. I've changed the input form to accept 75 chars and the database table to as well. But something in Django is still blocking this.

Any ideas?

UPDATE:

<form method="post" action="." class="full">
{% csrf_token %}
<ul>
    {% if form.non_field_errors %}<li>{{ form.non_field_errors }}</li>{% endif %}
    <li>
        {{ form.username.errors }}
        <label for="id_username">Email/Username</label>
        <input type="text" id="id_username" name="username" maxlength="75">
    </li>
    <li>
        {{ form.password.errors }}
        <label for="id_password">{{ form.password.label }}</label>
        {{ form.password }}
    </li>
</ul>
<input type="submit" value="Login">
<a href="{% url django.contrib.auth.views.password_reset %}">Forgot your password?</a>
</form>
like image 949
Brenden Avatar asked Oct 11 '22 11:10

Brenden


1 Answers

In the end, I fixed this by adding this to my top level init

# Added so the login field can take email addresses longer than 30 characters
from django.contrib.auth.forms import AuthenticationForm

AuthenticationForm.base_fields['username'].max_length = 150
AuthenticationForm.base_fields['username'].widget.attrs['maxlength'] = 150
AuthenticationForm.base_fields['username'].validators[0].limit_value = 150
like image 123
Brenden Avatar answered Oct 16 '22 08:10

Brenden