我已经写了下面的表单,从选择框中发送一些数据,但我发现django在完成网址上收到的唯一内容是csrf令牌。< / p>
这是我的表格:
<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>
在我的观点中,我检查了帖子数据,我得到的只是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)
答案 0 :(得分:1)
您的<select>
元素需要name
属性,而不仅仅是id
。该名称成为随表单提交的参数名称。例如,您的第一个<select>
应如下所示:
<select name="cinema" id="cinema" class=" form-control">
...
</select>