1👍
✅
def home(request):
if request.method == 'POST':
form = LoginForm(request.POST)
print('form:', form)
if form.is_valid():
print('username:', form.cleaned_data.get('username'))
print('password:', form.cleaned_data.get('password'))
print('niceee')
else:
form = LoginForm()
context = {}
return render(request, 'index.html', context)
Check the server for username and password values.
0👍
You are a halfway there! Once the form has been validated by Django, you can access the form’s variables in its cleaned_data
attribute:
def home(request):
context = {}
if request.method == 'POST':
form = LoginForm(request.POST)
print('form:', form)
if form.is_valid():
print('You submitted this username:', form.cleaned_data['username'])
print('You submitted this password:', form.cleaned_data['password'])
else:
return render(request, 'index.html', context)
else:
form = LoginForm()
However, consider reusing django.contrib.auth.views.LoginView
because then you won’t have to write any Python code at all. Just customize the registration/login.html
template.
- [Answered ]-Improving Django performance with 350000+ regs and complex query
- [Answered ]-Page not found (404) No x matches the given query
- [Answered ]-Django notification hq mark_as_read
- [Answered ]-Django not committing form to database
Source:stackexchange.com