我目前距离将显示器扔到墙上几分钟,所以如果有人可以帮我解决这个问题那就太棒了:)我已经制作了一个GET表格,一旦用户到达,我就会把你送到另一个页面此页面视图假设从URL中获取GET参数,然后决定要显示的内容。但是我遇到了我认为应该是一个简单的if语句的问题,if语句基本上是假设通过检查所有参数是否等于None来检查它们是否通过GET表单来到页面。但由于某些原因,即使所有参数都是None,它也不会检测到它。有谁能看到这个问题?
查看 -
def browse(request):
business_industry = request.GET.get('business_industry', None)
business_address_region = request.GET.get('business_address_region', None)
keywords = request.GET.get('keywords', None)
print(business_industry)
print(business_address_region)
print(keywords)
if business_industry and business_address_region and keywords is not None:
print("If")
else:
print("Else")
job_listings = JobListing.objects.exclude(active_listing=False)
context_dict = {
'joblistings': job_listings
}
return render(request, 'browse.html', context_dict)
表格 -
region_choice = (
(None, 'Region'),
('1', 'Auckland'),
('2', 'Wellington'),
('3', 'Christchurch')
)
suburb_choice = (
(None, 'None'),
('1', 'Glendowie'),
('2', 'Kohimarama'),
('3', 'Herne Bay')
)
industry_choice = (
(None, 'Business Industry'),
('1', 'Accounting'),
('2', 'Agriculture, fishing & forestry'),
('3', 'Automotive'),
('4', 'Banking, finance & insurance'),
('5', 'Construction & Architecture'),
('6', 'Customer service'),
)
employment_type_choice = (
(None, 'None'),
('1', 'Full Time'),
('2', 'Part Time'),
('3', 'One-off'),
('4', 'Other')
)
class JobQuickSearchForm(forms.Form):
business_address_region = forms.ChoiceField(region_choice, required=False, widget=forms.Select(attrs={'class': 'qs-form-input'}))
business_industry = forms.ChoiceField(industry_choice, widget=forms.Select(attrs={'class': 'qs-form-input'}))
keywords = forms.CharField(max_length=20, widget=forms.TextInput(attrs={'class': 'qs-form-input', 'placeholder': 'Enter Keywords...'}))
HTML -
<div id="quicksearch">
<h1 class="pageheader">Where would you to like to work?</h1>
<form class="qs-form" action="{% url 'browse' %}">
{{ form.non_field_errors }}
{{ form.business_industry }}
{{ form.business_address_region }}
{{ form.keywords }}<br>
<button type="submit" class="qs-form-button">Search Jobs</button>
</form>
</div>