0

I've been thinking of this for a LONG time the past few days and can't figure out with my current toolset how to implement this in Django.

What I want is something that can be implemented trivially in Java for example, but how I'd do that on the web is much more difficult

The problem

I want to send data to a HTML template, specific example:

"What is 5 + 50?"

The data must be dynamically generated, so the 5 and 50 are actually randomly generated.

I think I am comfortable doing this part, as I'd simply pass a random variable to a template using the views.py

This is where I do not know how to proceed

I want the user to be able to enter their answer, and have them notified if it correct.

To do this, I'd need to pass the variables from the template back to another view function. I am not sure how to do that, if it is possible at all.

This is how I'm deciding to pursue my projecti dea, and I'm not sure if this is the most efficient way

tl;dr I just wanted data to be randomly generated and calculated using Django

1 Answer 1

0

A pure django solution would be:

  • create a form with three integer fields (say, num1, num2 and result)
  • in your view, populate num1 and num2 with the numbers to be added
  • render the form in your template (num1 and num2 fields should be read only)
  • the user enters the answer in the result field and submits the form
  • in your view, determine whether num1 + num2 == result
  • redirect to a success page if the answer is correct, otherwise redisplay the form
Sign up to request clarification or add additional context in comments.

2 Comments

I didn't know you could make forms without a Model. Would it be something like this? stackoverflow.com/questions/17754295/…
Thanks will try implementing it tomorrow. Happy new years

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.