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
. I don't know why django is not redirecting me to the login_url_redirect
that is specified in the settings.py.
settings.py
AUTH_USER_MODEL = 'account.UserBase'
LOGIIN_REDIRECT_URL = '/account/dashboard'
LOGIN_URL = '/account/login'
urls.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'
Don't you have a typo on LOGIIN_REDIRECT_URL
? Shouldn't it be LOGIN_REDIRECT_URL
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.