I want to create a homepage with a header that asks to login with username/password and a login button to login. Currently, how I have my page set up is that pressing login
You can use Django's built in log in form. It is quit easy and efficient.And it will give you some features like form validation check.
in urls.py:
url(r'^login/$',views.loginView,name='login'),
in views.py:
from django.contrib.auth import login
from django.contrib.auth.forms import AuthenticationForm
def loginView(request):
if request.method == 'POST':
form = AuthenticationForm(data=request.POST)
if form.is_valid():
user = form.get_user()
login(request, user)
return redirect('/website/profile/')
else:
form = AuthenticationForm()
return render(request, 'website/login.html', {'form': form})
in html page: