Issue
I am trying to do search method in my_app. Code in my navbar.html is as below. It is not full code. The other buttons in the navbar work fine. These are not forms - just regular links.
<form class="d-flex" action="{% url 'search_record' %}" method="POST">
{% csrf_token %}
<input class="form-control me-2" type="text" placeholder="Search">
<button class="btn btn-primary" type="button">Search</button>
</form>
In my urls.py I have name "search_record"
urlpatterns = [
path('show/', show_record, name="show_record"),
path('new/', new_record, name="new_record"),
path('edit/<int:id>/', edit_record, name="edit_record"),
path('del/<int:id>/', delete_record, name="delete_record"),
path('search_record/', search_record, name="search_record")]
I have the appropriate entries in the file views.py
def search_record(request):
return render(request, 'my_app/search_record.html',
{})
And I also have a template file search_record.html in the directory templates/my_app whose content is as follows:
{% extends 'my_app/index.html' %}
{% block title %} Search Results {% endblock %}
{% block page %}
<h1>Results ...</h1>
{% endblock %}
When I am using the url: http://127.0.0.1:8000/my_app/search_record/ in the browser then search_record.html works good it shows me "Results ...", but clicking the Search button in the navbar does't work. After clicking this button, nothing happens. What am I doing wrong ? I have django 4 in my app.
Solution
i think change button type to submit cause you are submitting form on clicking that button
Answered By - Tejas Gosavi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.