python - How do I create a url in django and capture inputs for a search page? -
new django , programming.
i want create search page , have following.
my urlpatterns has following 1 of it's patterns.
url(r'^search/$', view=search, name='search')
my views has function
def search(request): if request.get.get('q'): message = 'you submitted: %r' % request.get['q'] else: message = 'you submitted nothing!' return render(request, 'myapp/search.html', {'message': message})
search.html has
<!doctype html> <html> <head> <title>search</title> </head> <body> <h1> search </h1> <form action="/search/" method="get" > <input type="text" name = "q"> <input type="submit"value="search"/> </form> </body> </html>
my issue when go "myapp/search" see search box , see in django debug toolbar "views.search" function captured, when enter text in search box , click "search" receive "the current url, search/, didn't match of these." plus django debug toolbar shows variable capture, nothing in views.
1) how associate 'views.search' after click 'search' button.
2) in url patterns need url pattern, if should be?
thanks
you said url "/myapp/search/", "action" parameter of form - determines form data sent - "/search/". need make same, data sent url.
the best way use {% url %}
tag:
<form action="{% url "search" %}" method="get">
Comments
Post a Comment