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 trialMike Nedelko
8,991 PointsSave button doesn't work in Make a new Quiz form
Hi Teamtreehouse
So I followed the tutorial, but seem to be stuck. My 'Make a New Quiz' form displays nicely, but upon filling in the form anc clicking 'Save' nothing happens.
Ant advice would be highly appreciated. Please see my workspace code below:
quiz_form.html
{% extends "courses/layout.html" %}
{% block title %} New Quiz | {{course.title }} {{ block.super}} {% endblock %}
{% block breadcrumbs %}
<li><a href="{% url 'courses:detail' pk=course.pk %}">{{ course.title }}</a></li>
{% endblock %}
{% block content %}
<div class="row columns">
{{ block.super }}
<h1>Make a new quiz</h1>
<from method="POST" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" class="button" value="Save">
</from>
</div>
{% endblock %}
views
@login_required
def quiz_create(request, course_pk): #we use course_pk to know course it belongs to
course = get_object_or_404(models.Course,pk =course_pk) #here we want to get the course this belongs to first
form = forms.QuizForm() #here we want to make a blank form first.
if request.method == "POST": #someone has posted our form
form = forms.QuizForm(request.POST) #this is the data the user entered in
if form.is_valid():
quiz = form.save(commit=False)
quiz.course = course
quiz.save()
messages.add_message(request, messages.SUCCESS,
"Quiz added!")
return HttpResponseRedirect(quiz.get_absolute_url())
return render(request, 'courses/quiz_form.html', {'form':form, 'course':course})
2 Answers
Mike Nedelko
8,991 PointsThanks Chris. Really appreciate it. Found the error... instead of writing <form> I wrote <from> ... ... ...
Chris Freeman
Treehouse Moderator 68,441 PointsThe HTML form requires an action value:
The URI of a program that processes the form information. This value can be overridden by a formaction attribute on a <button> or <input> element.