简体   繁体   English

登录未重定向到 django 上的指定 url

[英]Login not redirecting to the specified url on django

I want to be redirected to the dashboard page in the website but I'm being redirected to a different url which is not specified in django url and as a result I'm getting page not found error .我想被重定向到网站中的仪表板页面,但我被重定向到另一个 url 未在 django url 中指定,因此我page not found error I don't know why django is not redirecting me to the login_url_redirect that is specified in the settings.py.我不知道为什么 django 没有将我重定向到 settings.py 中指定的login_url_redirect

settings.py
AUTH_USER_MODEL = 'account.UserBase'
LOGIIN_REDIRECT_URL = '/account/dashboard'
LOGIN_URL = '/account/login'

urls.py网址.py

url.py(in the main django app)
urlpatterns = [
    path('account/', include('account.urls', namespace='account')), 
]
urls.py (for the given app)
urlpatterns = [
     path('login/', auth_views.LoginView.as_view(template_name='account/registration/login.html', form_class=UserLoginForm), name='login'),
     path('register/', views.account_register, name='register'),
     path('dashboard/', views.dashboard, name='dashboard'),
]

template模板

<form class="account-form p-4 rounded" action="{% url 'account:login' %}" method="post">

                                {% csrf_token %}
                                <h3 class="mb-4">Sign In</h3>

                                {% if form.errors %}
                                <div class="alert alert-primary" role="alert">
                                    Error: Username or Password not correct!
                                </div>
                                {% endif %}

                                <label class="form-label">{{ form.username.label}}</label>
                                {{ form.username}}

                                <label class="form-label">{{ form.password.label}}</label>
                                {{ form.password}}
                                <div class="d-grid gap-2">
                                    <input type="hidden" name="next" value="{{ next }}">
                                    <button class="btn btn-primary py-2 mb-4 mt-5 fw-bold" type="submit" value="Log-in">Sign in
                                    </button>
                                </div>
                                <p class="text-center pb-3">
                                    <a href="{% url "account:register" %}">Create an account</a>
                                </p>
                            </form>

I want someone to help me pinpoint the reason why I'm not redirected to this url specified in settings.py LOGIIN_REDIRECT_URL = '/account/dashboard'我希望有人帮我查明为什么我没有重定向到 settings.py LOGIIN_REDIRECT_URL = '/account/dashboard'中指定的这个 url 的原因

Don't you have a typo on LOGIIN_REDIRECT_URL ?您在LOGIIN_REDIRECT_URL上没有错字吗? Shouldn't it be LOGIN_REDIRECT_URL ?不应该是LOGIN_REDIRECT_URL吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM