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开发者_如何学C 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>
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
Just to check, did you change the field length of username in django.contrib.auth.models.User from 30 to 75, then drop the old auth table from the db, grab fresh SQL to create the auth table by running manage.py sqlall, and execute this SQL to create the new table with the updated field length?
(Since this is just a follow up question, I'd leave it in a comment but don't have quite enough rep yet...)
精彩评论