Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!