I try
render to context with the extra argument
importing the class csrf_protect and used as decorator.
and looks like if you use the "render" function should be the easiest way since will take care of everything.
I also tried removing the tags from the html and I still get the error.
I am missing to put something?
2 extra questions.
can I use my own forms with django done in a html file? or they have to be django forms? (as I understand the django forms are premade so its easy to use them and render the windget? like a calendar widget)
now that I have the form and the submit how can I pass the info of the form to the next webpage, example
so it say thank you for voting + the email they typed in the form.
thanks guys =p
my views
#import django stuff
import django
from django.shortcuts import render, render_to_response
from django.http import HttpResponse
from django.template import Template, Context
from django.http import HttpResponseRedirect
from django.core.context_processors import csrf
from django.views.decorators.csrf import csrf_protect
from django.template import RequestContext
#importing tables---
from polls.models import Restaurant
from polls.models import Dish
#importing forms---
import polls.forms_DK
def main_site(request):
return render_to_response('initial_page.html')
def vote(request):
if request.method == "POST":
form = polls.forms_DK.NameForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('/thanks')
else:
form = polls.forms_DK.NameForm()
django.setup()
all_restaurants = Restaurant.objects.all()
return render_to_response("vote_form.html", {"all_restaurants": all_restaurants, "form": form})
def thanks(request):
c = {"thanks_body": "thanks_body"}
return render(request, "thanks.html", c)
my forms.py
from django import forms
from polls.models import Restaurant
import django
class NameForm(forms.Form):
your_email = forms.EmailField()
django.setup()
all = Restaurant.objects.all()
options_ratio = []
for i in all:
mini_list = []
mini_list.append(i.id)
mini_list.append(i.name)
options_ratio.append(mini_list)
ratio = forms.ChoiceField(choices=options_ratio, widget=forms.RadioSelect())
the html
{% extends "initial_page.html" %}
{% block body %}
<p>Vote for the restaurant of your choise</p>
<form action="/polls/vote/thanks/" method="post">{% csrf_token %}
{{ form }}
<input type="submit" value="Submit" />
</form>
{% endblock %}