Skip to main content
deleted 9 characters in body
Source Link
Sunderam Dubey
  • 8.8k
  • 12
  • 26
  • 43

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL and view so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login'

    def get_success_url(self):
        user=self.request.user.username
        return reverse('home', args=(user))

In settings.py:

LOGIN_URL='some_app_name:login' #Redirect to login page if not logged in.

LOGIN_REDIRECT_URL='some_app_name:home' #Redirect to home page after successful login

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

Note: It's not a good practice to name same your view with actual authentication view so it should be MyLoginView or anything you can give instead of actual view name.

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL and view so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login'

    def get_success_url(self):
        user=self.request.user.username
        return reverse('home', args=(user))

In settings.py:

LOGIN_URL='some_app_name:login' #Redirect to login page if not logged in.

LOGIN_REDIRECT_URL='some_app_name:home' #Redirect to home page after successful login

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

Note: It's not a good practice to name same your view with actual authentication view so it should be MyLoginView or anything you can give instead of actual view name.

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login'

    def get_success_url(self):
        user=self.request.user.username
        return reverse('home', args=(user))

In settings.py:

LOGIN_URL='some_app_name:login' #Redirect to login page if not logged in.

LOGIN_REDIRECT_URL='some_app_name:home' #Redirect to home page after successful login

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

Note: It's not a good practice to name same your view with actual authentication view so it should be MyLoginView or anything you can give instead of actual view name.

added 97 characters in body
Source Link
Sunderam Dubey
  • 8.8k
  • 12
  • 26
  • 43

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL and view so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login' 

    def get_success_url(self):
        user=self.request.user.username
        return reverse('home', args=(user))

In settings.py:

LOGIN_URL='some_app_name:login' #Redirect to login page if not logged in.

LOGIN_REDIRECT_URL='some_app_name:home' #Redirect to home page after successful login

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

Note: It's not a good practice to name same your view with actual authentication view so it should be MyLoginView or anything you can give instead of actual view name.

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL and view so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login'

In settings.py:

LOGIN_URL='some_app_name:login' #Redirect to login page if not logged in.

LOGIN_REDIRECT_URL='some_app_name:home' #Redirect to home page after successful login

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL and view so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login' 

    def get_success_url(self):
        user=self.request.user.username
        return reverse('home', args=(user))

In settings.py:

LOGIN_URL='some_app_name:login' #Redirect to login page if not logged in.

LOGIN_REDIRECT_URL='some_app_name:home' #Redirect to home page after successful login

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

Note: It's not a good practice to name same your view with actual authentication view so it should be MyLoginView or anything you can give instead of actual view name.

deleted 103 characters in body
Source Link
Sunderam Dubey
  • 8.8k
  • 12
  • 26
  • 43

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL and view so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login'
    login_redirect_url='home'

    def get_success_url(self)

In settings.py:

LOGIN_URL='some_app_name:
 login' #Redirect to login page if not logged user=self.request.userin.username
  
LOGIN_REDIRECT_URL='some_app_name:home' #Redirect to home page after returnsuccessful f'/{user}/'login

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL and view so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login'
    login_redirect_url='home'

    def get_success_url(self):
         user=self.request.user.username
        return f'/{user}/'

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

You can use settings.LOGIN_URL and settings.LOGIN_REDIRECT_URL and view so:

class LoginView(LoginView):
    template_name = 'login.html'
    login_url='login'

In settings.py:

LOGIN_URL='some_app_name:login' #Redirect to login page if not logged in.

LOGIN_REDIRECT_URL='some_app_name:home' #Redirect to home page after successful login

It defaults to LOGIN_URL and LOGIN_REDIRECT_URL of settings.py if not specified in views.

Source Link
Sunderam Dubey
  • 8.8k
  • 12
  • 26
  • 43
Loading