i cant redirect to a specific page after login

i cant login and after loging i cant redirect to homepage. my code is added below. any idea why?


def login_view(request):
    members = Users.objects.all()

    auth = False

    if request.method == 'POST':
        username = request.POST['username']
        password = hashlib.md5(request.POST['password'].encode('utf-8')).hexdigest()
        user = authenticate(username=username, password=password)
        if user is not None:
            login(request, user)
        return redirect(profile_view)
    context = {
        'nav': 'APP | Login',
        'navoptions': ['registration',]
    return render(request, 'home-login.html', context=context)

profile view

def profile_view(request):
    #if request.user.is_authenticated:
    id = request.user
    context = {
        'nav': id,
        'user': id,
        'option': option,
        'navoptions': ['home', 'courses', 'news', 'Sign Out']
    return render(request, 'profile.html', context=context)


urlpatterns = [
    path('admin/', admin.site.urls),
    path("", login_view, name='home-login'),
    path("signup_user/", signup_view, name='registration'),
    path("profile/", profile_view, name='profile'),

below is what i added in settings.py as mentioned is some online page.


i think even after i changed the login redirect, its still looking for the default login url.
below is the error i get in the browser:

It’s the LOGIN_URL setting that defines what url a user will go to if they try to go to a “login_required” page.

The LOGIN_REDIRECT_URL is the url you will be sent to after you have logged in.

Also, there’s no need or value to having the line:

in your login_view.

Side note: I recommend that you do not make your base url (or blank url) your login page.

1 Like