Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda