当用户点击页面上的按钮“submit”时,我想调用python函数http://junjob.ru/accounts/login/
我该怎么做?
我的代码:
视图.py
class BBLoginView(LoginView):
template_name = 'vacancy_list/login.html'
class BBLogoutView(LoginRequiredMixin, LogoutView):
template_name = 'vacancy_list/vacancy_list.html'
next_page = reverse_lazy('vacancy_list')
url.py
urlpatterns = [
path('accounts/login/', BBLoginView.as_view(), name='login'),
path('accounts/profile/', profile, name='profile'),
path('accounts/logout/', BBLogoutView.as_view(), name='logout'),
...
登录.html
{% block content %}
<div class="container" style="margin-top:10px">
<h2>Login</h2>
{% if user.is_authenticated %}
<p>You are already registered</p>
{% else %}
<form method="post">
{% csrf_token %}
{% bootstrap_form form layout='horizontal' %}
<input type="hidden" name="next" value="{{ next }}">
{% buttons submit="Submit" %} {% endbuttons %}
</form>
{% endif %}
</div>
{% endblock %}
您可以连接到父类
LoginView
的form_valid
方法:如果只有窗体有效但在用户身份验证之前,它将触发
如果您需要在任何情况下执行代码,请挂接到
post
方法:您可以找到
LoginView
here的源代码相关问题 更多 >
编程相关推荐