Skip to content

Commit

Permalink
misc: add sample form for quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowtham1729 committed Nov 5, 2023
1 parent b93e6aa commit d612bce
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
5 changes: 5 additions & 0 deletions applications/backend/django_server/news/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django import forms


class InputForm(forms.Form):
user_input = forms.CharField(label="Enter your text", max_length=100)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Display Input</title>
</head>
<body>
<p>You entered: {{ user_input }}</p>
</body>
</html>
13 changes: 13 additions & 0 deletions applications/backend/django_server/news/templates/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>User Input</title>
</head>
<body>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
</body>
</html>
3 changes: 2 additions & 1 deletion applications/backend/django_server/news/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
from . import views

urlpatterns = [
path("", views.index, name="index"),
path("", views.input_view, name="input"),
path("display/", views.display_view, name="display"),
]
20 changes: 19 additions & 1 deletion applications/backend/django_server/news/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.shortcuts import redirect, render

from .forms import InputForm


# Create your views here.
Expand All @@ -10,3 +12,19 @@ def index(request):
"status": "ok",
}
)


def input_view(request):
if request.method == "POST":
form = InputForm(request.POST)
if form.is_valid():
request.session["user_input"] = form.cleaned_data["user_input"]
return redirect("display")
else:
form = InputForm()
return render(request, "input.html", {"form": form})


def display_view(request):
user_input = request.session.get("user_input", "No input provided")
return render(request, "display.html", {"user_input": user_input})

0 comments on commit d612bce

Please sign in to comment.