Wednesday, January 8, 2014

The basic admin page

Okay, now that we have created a project, let's proceed to the actual programming. Open the folder named 'mysite'.
cd mysite

We will initially use SQLite as our database engine. Although it is much less powerful than MySQL, it is easy to implement and convenient for testing. We can then upgrade to MySQL

In the 'mysite' directory, create a file called 'trial.db'. This is the database we will be using.

Open the 'settings.py' file. On line 14, in DATABASES, set 'ENGINE' to 'sqlite3'.
'ENGINE' : 'sqlite3'

In 'NAME', give the path to your 'trial.db' file.

Now scroll down to line 115, in 'INSTALLED_APPS'. You will see two lines saying 'Uncomment the next line...' Uncomment the lines under both the comments.

In the same INSTALLED_APPS, add the line 'mysite.website', This line will tell django that website is an app that is to be included. DO NOT FORGET THE COMMA.

Now go to the file called 'urls.py'. Uncomment lines 4, 5, 13, and 16.

You're set! Open the terminal, and type the following:

python manage.py syncdb

This command tells django to synchronize the database. It will ask you to create a super user. Do so. Run the command again. This time you will see a far shorter number of lines in the terminal. Once this is done, type the following:

python manage.py runserver

This command starts the development server on which we shall see the execution of the code. It will tell you to go to http://127.0.0.1/, which is localhost. Go to that url and you will see a success message.
After that, go to this url:   http://127.0.0.1/admin/

You will see a login page. Log in as the super user you created earlier for the syncdb command, and you will be redirected to a control panel.

That's all for now! Feel free to ask doubts in the comments. I may have left something out. You can also send me an email on the id specified. Adios!

No comments:

Post a Comment