在bootstrap popover中发布不在表单中的操作

时间:2017-11-04 06:43:40

标签: html django twitter-bootstrap-3 popover

我正在尝试从输入字段中保存一个url(表单在bootstrap popover中)但是当我单击“保存”按钮时没有任何反应。 这是我的HTML代码:

<div id="popover-content" class="hide">

<form name ="bform" method = "post" action = "{% url 'savebookmark' %}" class ="form-inline">
 {% csrf_token %}
  <div class="form-group">
  <input placeholder = "http://..." name = "url" class = "form-control" type = "text">
  <button type = "button" class = "btn btn-danger">Save</button>
  </div>
  </form>
</div>

views.py

def save_bookmark(request):

bmark = request.POST.get("url")
user = user
obj = UserBookmark(user_id=user,bookmark=bmark)
obj.save()
return HttpResponse("Data saved")

urls.py

 urlpatterns = [
 url(r'^$', views.index, name='index'),
url(r'^register/$',views.register, name='register'),
url(r'^login/$',views.login_view, name='login'),
url(r'^register/success/$',views.register_success, name='register_success'),
url(r'^category/$',views.get_category,name='getcategory'),
url(r'^#/$',views.save_bookmark,name='savebookmark'),
]

请指导我在这方面做错了什么?

1 个答案:

答案 0 :(得分:1)

表单不起作用,因为您没有使用SUBMIT按钮提交表单

<div id="popover-content" class="hide">

<form name ="bform" method = "post" action = "{% url 'savebookmark' %}" class ="form-inline">
 {% csrf_token %}
  <div class="form-group">
  <input placeholder = "http://..." name = "url" class = "form-control" type = "text">
  <button type = "submit" class = "btn btn-danger">Save</button>
  </div>
  </form>
</div>

使用此功能,希望它可以根据您的需要使用