更改 bootstrap4 按钮“搜索”文本
Posted
技术标签:
【中文标题】更改 bootstrap4 按钮“搜索”文本【英文标题】:Change bootstrap4 button "search" text 【发布时间】:2020-03-29 17:46:16 【问题描述】:当我点击我网站上的“搜索”按钮时http://junjob.ru/ 我去http://junjob.ru/search/?q=&q2=ALL
如何在此链接中将文本“search”更改为“my_search”? 我需要http://junjob.ru/my_search/?q=&q2=ALL
我正在使用 django 网络框架。并且修复应该支持来自表单的查询
我的代码
vacancy_list.html
<div class="container" style="margin-top: 40px; font-size: 2rem; padding-left: 0px;">
<form action="% url 'search_results' %" method="get">
<div class="row">
<div class="col-lg-8 col-md-6 col-xs-12">
<input name="q" type="text" placeholder="Search..." class="form-control">
</div>
<div class="col-lg-3 col-md-4 col-xs-12">
<select name="q2" class="form-control" id="exampleFormControlSelect1">
<option>Other</option>
</select>
</div>
<div class="col-lg-1 col-md-2 col-xs-12" style="padding-left: 0px;">
<button class="btn btn-primary">Search</button> <!-- BUTTON -->
</div>
</div>
</form>
</div>
views.py
class HomePageView(ListView):
model = Vacancy
template_name = 'vacancy_list/vacancy_list.html'
paginate_by = 5
page_kwarg = 'vacancy'
context_object_name = 'vacancies'
queryset = Vacancy.objects.order_by('-published_date')
def paginate_queryset(self, queryset, page_size):
"""Paginate the queryset, if needed."""
paginator = self.get_paginator(
queryset, page_size, orphans=self.get_paginate_orphans(),
allow_empty_first_page=self.get_allow_empty())
page_kwarg = self.page_kwarg
page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1
try:
page_number = int(page)
except ValueError:
if page == 'last':
page_number = paginator.num_pages
else:
raise Http404(_('Page is not “last”, nor can it be converted to an int.'))
try:
page = paginator.page(page_number)
return (paginator, page, page.object_list, page.has_other_pages())
except InvalidPage as e:
raise Http404(_('Invalid page (%(page_number)s): %(message)s') %
'page_number': page_number,
'message': str(e)
)
def vacancy_detail(request, pk):
vacancy = get_object_or_404(Vacancy, pk=pk)
print("ZZZZZZ: ;;VACANCY;;\n".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), request.user, pk))
log_to_file(";;VACANCY;;\n".format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), request.user, pk))
return render(request, 'vacancy_list/vacancy_detail.html', 'vacancy': vacancy)
urls.py
urlpatterns = [
path('', HomePageView.as_view(), name='vacancy_list'),
path('search/', SearchResultsView.as_view(), name='search_results'),
path('vacancy/<int:pk>/', views.vacancy_detail, name='vacancy_detail'),
path('company/<int:pk>', views.company_detail, name='company_detail'),
path('vacancy/<int:pk>/request', contact_us, name='contact_us'),
...
【问题讨论】:
【参考方案1】:你应该改变你的蛞蝓;
urlpatterns = [
path('my_search/', SearchResultsView.as_view(), name='search_results'),
接下来,您必须进行 makemigrations 和 migrate
【讨论】:
【参考方案2】:如果您想更改网址,只需编辑您的 urls.py
文件:
urlpatterns = [
path('my_search/', SearchResultsView.as_view(), name='search_results'),
...
请记住,当您使用 nameed 网址时,无需对它们进行硬编码,您无需更改 html 模板。
【讨论】:
【参考方案3】:path('my_search/', SearchResultsView.as_view(), name='search_results')
【讨论】:
以上是关于更改 bootstrap4 按钮“搜索”文本的主要内容,如果未能解决你的问题,请参考以下文章