Pass user input to server
<form method="GET" action="/search/">
<fieldset>
<caption> Search </caption>
<input type="text" name="q">
<button type="submit">Search</button>
</fieldset>
</form>
<form method="POST" action="/login/">
<formset>
<caption> Log In </caption>
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">Log In</button>
</formset>
</form>
from django import forms
class LoginForm(forms.Form):
username = forms.TextField()
password = forms.PasswordField()
from .forms import SearchForm
def login(request):
if request.method == 'POST':
form = SearchForm(request.POST)
if form.valid():
...
return redirect(request.user)
else:
form = SearchForm()
return render(request, 'login.html', {'form': form})