簡體   English   中英

我在表單中的操作 url 做錯了什么

[英]What am I doing wrong with action url in my form

我正在嘗試在 my_app 中執行搜索方法。 我的navbar.html中的代碼如下。 它不是完整的代碼。 導航欄中的其他按鈕工作正常。 這些不是 forms - 只是常規鏈接。

<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>

在我的urls.py我有名字“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")]

我在文件views.py中有適當的條目

def search_record(request):
return render(request, 'my_app/search_record.html', 
    {})

而且我在templates/my_app目錄下還有一個模板文件search_record.html,內容如下:

{% 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'不工作。 單擊此按鈕后,沒有任何反應。 我究竟做錯了什么? 我的應用程序中有 django 4 。

我認為更改按鈕類型以提交因為您在單擊該按鈕時提交表單

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM