I've written the form below to send some data from the select boxes but I've found out that the only thing that's received by django on the completion url is the csrf token.
我写了下面的表格从选择框发送一些数据,但我发现django在完成URL上收到的唯一内容是csrf令牌。
Here's my form:
这是我的表格:
<form class="form-horizontal" method="post" action="{% url 'movie_results' %}">{% csrf_token %}
<div class="form-group">
<label for="inputEmail3" class="col-xs-2 control-label">Select Cinema</label>
<div class="col-xs-10">
<select id="cinema" class=" form-control">
<option></option>
{% for node in venues %}
<option class="" value="{{ node.slug }}">{{ node.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-2 text-right">
<label for="inputPassword3" class="control-label">Select Movie</label>
<img class="movie-gif hidden" src="{{ STATIC_URL }}kb/images/ajax-loader.gif" style="">
</div>
<div class="col-xs-10">
<select id="movie2" class=" form-control">
<option></option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-2 text-right">
<label for="inputPassword3" class="control-label">Select Date</label>
<img class="date-gif hidden" src="{{ STATIC_URL }}kb/images/ajax-loader.gif" style="">
</div>
<div class="col-xs-10">
<select id="dates" class=" form-control">
<option></option>
</select>
</div>
</div>
<div id="movies-button" class="form-group">
<div class="col-xs-12">
<button type="submit" id="find-show" class="btn btn-danger">FIND SHOW TIMES</button>
</div>
</div>
</form>
And here's my view, I've checked the post data and all i get is the csrf token. I can confirm there's post request since the variables are only calculated if there's a post request.
这是我的观点,我检查了帖子数据,我得到的是csrf令牌。我可以确认有帖子请求,因为只有在有帖子请求的情况下才会计算变量。
def search(request, template_name='mobile/movies_search.html'):
context = RequestContext(request)
if request.method == 'POST':
cinema = request.POST.get('cinema','None')
movie = request.POST.get('movie2','None')
post = request.POST
today = datetime.date.today()
qs = Show.objects.filter(starts__gte=today)
if cinema and cinema != "None":
qs = qs.filter(venue__slug=cinema)
if movie and movie != "None":
qs = qs.filter(movie__name=movie)
if date and date != "None":
day,month,year = date.split('-')
qs = qs.filter(starts__year = year, starts__day = day, starts__month=month, )
movies = list(set([x.movie for x in qs]))
context['movies'] = movies
context['movie'] = movie
context['cinema'] = cinema
context['post'] = post
return render_to_response(template_name, context)
1 个解决方案
#1
1
Your <select>
elements need to have a name
property, not just an id
. The name is what becomes the parameter name that gets submitted with the form. For example, your first <select>
should look like this:
您的应如下所示:
<select name="cinema" id="cinema" class=" form-control">
...
</select>
#1
1
Your <select>
elements need to have a name
property, not just an id
. The name is what becomes the parameter name that gets submitted with the form. For example, your first <select>
should look like this:
您的应如下所示:
<select name="cinema" id="cinema" class=" form-control">
...
</select>