Python Forum

Full Version: How to get back a subdirectory in URL with Django
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I'm currently learning Django and i've come up with a difficulty. I have a login app, where the user logs in and registers, their url is localhost:8000/login. As soon as the user takes their login I want the URL to be localhost:8000/app. I tried to use LOGIN_REDIRECT_URL, but it didn't work. Any idea how I do that?

project/urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('', include('page.urls')),
    path('app/', include('home.urls'), name='home'),
    path('admin/', admin.site.urls),
]
login/views.py
@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect('/login/')

def login_user(request):
    if request.method == "POST":
        username = request.POST.get("username")
        password1 = request.POST.get("password1")
        user = authenticate(request, username=username, password=password1)

        if(user):
            login(request, user)
            HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
project/settings.py
LOGOUT_REDIRECT_url = '/'

LOGIN_REDIRECT_URL = 'home'  # nome da url
when I log in with the credentials the login page is rendered again
Did you import the settings from the right path?