please help to fix the authorization process.
I create the form AuthenticationCustomForm (inheriting from AuthenticationForm): from django.contrib.auth.forms import AuthenticationForm
class AuthenticationCustomForm(AuthenticationForm): username = forms.CharField( label='Имя пользователя', widget=forms.TextInput(attrs={ 'placeholder': 'Логин', }), ) password = forms.CharField( label='Пароль', widget=forms.PasswordInput(attrs={ 'placeholder': 'Пароль', }), )
views.py:
def login(request): if(request.method == "POST"): form = AuthenticationCustomForm(request.POST) with open(os.path.join(settings.BASE_DIR, "1.txt"), "wb") as f: f.write(bytes('1', 'UTF-8')) if form.is_valid(): with open(os.path.join(settings.BASE_DIR, "2.txt"), "wb") as f: f.write(bytes('2', 'UTF-8')) username = request.POST.get('username', '') password = request.POST.get('password', '') user = auth.authenticate(username=username, password=password) if user is not None and user.is_active: auth.login(request, user) return HttpResponseRedirect('/' + str(request.user.pk) + '/') else: form = AuthenticationCustomForm() t = loader.get_template('accounts/login.html') c = RequestContext(request, { 'form': form, }, [custom_proc]) return HttpResponse(t.render(c))
login.html: {% for field in% form} {{field.error}} {% endfor%}
<form class="login_form" action="{% url 'login' %}" method="post"> {% csrf_token %} <div class="cell"> {{ form.username }} {{ form.username.errors }} {{form.non_field_errors}} </div> <div class="cell"> {{ form.password }} {{ form.password.errors }} {{form.non_field_errors}} </div> <div class="cell"> <input class="submit btn btn-info" type="submit" value="Войти" /> </div> </form>
urls.py:
url(r'^accounts/login/$', 'views.login', name='login', ),
as a result, the user cannot enter through this form even if he enters the correct login and password (remains on the same screen, the validation error message is not displayed on the screen). this creates a debug file "1.txt", but does not create a "2.txt"
Is it possible to offer a solution based on the standard logic for this situation? without using ninja techniques (only those who have been offered this at the stack carrier yet, and they work crookedly)