2.Add below two lines at the end of settings.py to use home.html as default home page
LOGIN_REDIRECT_URL = ‘home’
LOGOUT_REDIRECT_URL = ‘home’
Now copy and paste below code to your url.py (After removing everything from urls.py)
Once you have done above steps successfully, run below command in cmd to migrate
python manage.py migrate
And run Django server by executing below command in cmd
python manage.py runserver
Now open http://127.0.0.1:8000/in your web browser. You can see a link is showing called login. If you click on it will redirect you to the login form, where you need to provide user name and password.
Create user Djanog
But you can not log in now as you have not created any authenticated user name with password right. So lets create a user from django admin page.
To do so first you should create admin user name and password for your project. To do that type below command in cmd.
python manage.py createsuperuser
Once you execute above command, it will ask for
1.Username (which you needs to provide to login as admin). Give some name and enter.
django create super user
Now run server again and open http://127.0.0.1:8000/admin/ . Now login with your admin username and password (which you have created just above).
After login, create user by providing Username and Password and save it.
django create user
Now try to login here http://127.0.0.1:8000/ by providing user name and password which you have just created. It should login successfully and logout.
In this tutorial you have learned you to create basic login logout system by using default authentication system of Django. In my next article I will show you how to make this login and logout system stylish and attractive.
If you have any question or suggestion regarding this topic see you in comment section. I will try my best to answer.