Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Igors Smirnovs
10,441 PointsThe best method for building POLLS/Quizzes ?
Hey, can someone help me to find a solution please? What would be the best method for building a poll?
I explored this topic and as I understand it can be built as with python's framework as well as with JS/Ajax? If I use Flask should submission of a form be the only way or is there something else? Also how to make users submit their answers only once, maybe capture ip and record it in the database? Or should I better go for JS and why? Thanks. (P.S. I am not familiar with JS/Ajax).
1 Answer
Iain Simmons
Treehouse Moderator 32,305 PointsYou can definitely do this without JavaScript and Ajax, using Flask and probably Flask-WTF to generate HTML forms for your Poll/Quiz.
Here are some examples of varying complexity:
Without JavaScript, yes, submission of the form would be the only (sensible) way to do it. That's the way you would want to do it anyways, so you can handle the different routes and request types (POST when they submit their response/answer, GET when displaying questions or results).
IP address would be one way of determining a 'unique' user, but the majority of people will have a dynamic IP assigned by their ISP, so if they disconnected and reconnected to the internet, they would be given a new IP and treated as a new user.
Another method would be to implement some sort of registration process, storing user details in the database and associating them with their responses. Obviously that's a bit more complicated, so if you're only mildly concerned about people submitting more than once, maybe the IP address or a simple cookie would be sufficient to determine if they have submitted before or not.
The last example I provided above uses a Facebook login.
As for JavaScript and Ajax, they are normally used to provide some additional feedback and/or validation on the client side, to help users fill out the form. They can also be used to send requests and display responses from your Flask app without navigatin away or refreshing the page, making it seem quicker and more seamless.
Might be a good reason to take some JS courses on Treehouse!