Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
Django: redirecting URL from auto-generated "?search_bar="

So I am a new Django programmer and was wondering about how to pass a user-given value from a form into my URL address using Get method.

So I have this search bar, and when the user presses enter, it automatically creates a url address of "?search_bar=user_input"

But my urls.py, which is programmed to take the user_input variable, now fails to recognize my url address and my address is no longer matched to proceed to view.py.

urls.py

urlpatterns = [
    url(r'^class/(?P<user_input>\w+)', views.newview),
]

I understand that you cannot simply do the following because you shouldn't match query string with URL Dispatcher

urlpatterns = [
    url(r'^class/?search_bar=(?P<user_input>\w+)', views.newview),
]

I should I solve this issue? How can I make the url.py recognize my new address and carry the user_input over to views.py?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

when we talk about url like something/?search_bar=user_input ,something/ is the url part, and the ?search_bar=user_input part belongs to the GET method,so :

urls.py

urlpatterns = [
    url(r'^class/$', views.newview),
]

and in your view.py:

def newview(request):
    user_input = request.GET['user_input']
    # or
    # user_input = request.GET.get('user_input', None)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda