Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Django-成功消息Mixin在登录时不起作用_Html_Django - Fatal编程技术网

Html Django-成功消息Mixin在登录时不起作用

Html Django-成功消息Mixin在登录时不起作用,html,django,Html,Django,我正在尝试使用SuccessMessagexin在登录时显示成功消息,但未显示该消息。这有什么原因吗 设置.py LOGIN_REDIRECT_URL = 'home' LOGIN_URL = 'login' LOGOUT_REDIRECT_URL = 'home' LOGOUT_URL = 'logout' url.py from .views import HomeView, LoginFormView urlpatterns = [ path('admin/', admin.

我正在尝试使用SuccessMessagexin在登录时显示成功消息,但未显示该消息。这有什么原因吗

设置.py

LOGIN_REDIRECT_URL = 'home'
LOGIN_URL = 'login'

LOGOUT_REDIRECT_URL = 'home'
LOGOUT_URL = 'logout'
url.py

from .views import HomeView, LoginFormView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('home/', HomeView.as_view(), name = 'home'),
    path('login/', LoginFormView.as_view(), name = 'login'),
]
views.py

class HomeView(FormView):
    template_name = 'home.html'

class LoginFormView(auth_views.LoginView, SuccessMessageMixin):
    template_name = 'login.html'
    success_url = 'home/'
    success_message = "You were successfully logged in."
login.html

<h4>Login to your Account:</h4>
<div>
    <form action "" method = "POST">
        {% csrf_token %}
        {{form}}
        <button type = "submit">Login</button>
    </form>
</div>

按照继承顺序,
successessagexin
需要在之前(或至少在泛型视图之前),即它应该是
LoginFormView(successessagexin,auth_views.LoginView)
而不是
LoginFormView(auth_views.LoginView,successessessagexin)

classloginformview(成功消息gexin,auth_views.LoginView):
模板名称='login.html'
success\u url='home/'
success\u message=“您已成功登录。”

谢谢。我也很感激你的解释!
{% if messages %}
        {% for message in messages %}
            {{ message }}
        {% endfor %}
{% endif %}