Be Coded….


Create you first app using Django

This is the continuation from previous post, where we learned how to install Django and run server. Now lets create first app using Django.

Before creating our first app lets try to login to Django server has ADMIN. For that we need to create one super user account.
python createsuperuser
Above command will ask for Username, Email, Password. I recommend to keep default user name and Email ID, however Password you need to specify.

After creating Super user successfully, you need to migrate the changes you have done.
python showmigrations
Above command will shows the list of change or need to migrate.
python migrate

Assuming our server is still running in one side, we will open below mentioned link:

Use your user name and password you previously created. If you are able to login successfully, then you seen site administration layout.

If you click on User then you will see your super user details.

Lets create our first app – Django

Will create one Directory called src. And Run the below command:
django-admin startproject trydjango . (This is the same command used in the previous post, you can use existing or you can Re – create one).
At first we need to understand files created under trydjango directory. In brief we will move directly towards only one file called . Here in is used for application definitions.

In you will see one line called INSTALLED_APPS where it is used to define your models/project definitions here.
Lets create another module called “Products”. for that you need to run below command.
python startapp products
Above command will create new project module with respect to trydjango project. Once command is ran successfully some python files are created like, etc.
But we will use mainly and for our project. Lets start coding.
Open and add below mentioned code.

Above are the built-in function of Django where you can find more details here.
And also you need to register you model called “Product” should be registered in the file.

After that adding your app or hooking up you product module in the file so that it can directed toward Django server.

This image has an empty alt attribute; its file name is image-7-1024x829.png

Next task is to run one command whenever changes are done to any files in the directory, otherwise changes will not be migrated to DB or you root file.

python migrate
Once migration is done successfully, assuming our server is running in one side, we will move to “”

Click on add button. Then you will see three text box where you created in the file.

Add the values and click on save. Then you will see the Content you enter in the
Text box has been saved successfully.

So finally we are done with creating First using Django.

Below are the some useful links :

Comments are Closed

Theme by Anders Norén