Saturday, 2 August 2014

how start your first django programing

Standard

this framework so easy and nice it just write little and get more

Django is an MVC framework. However, the controller is called the "view", and
the view is called the "template". The view in Django is the component which
retrieves and manipulates data, whereas the template is the component that presents data to the user. For this reason, Django is sometimes called an MTV framework (MTV stands for model template view). This different terminology not changes the fact that Django is an MVC framework, nor affects how applications are developed. But keep the terminology in mind to avoid possible confusion if you have worked with other MVC frameworks in the past

now i will create a empty project



create a empty folder like "django" just for collection

To create your first Django project, open a terminal type the following command, and hit enter:

$cd django
$ django-admin.py startproject store

 This command will make a folder named store in the current directory, and create the initial directory structure inside it. where you can see kinds of file created like:

store/
      __init__.py (django project is a python package so and this file create
                           current folder like a package)
      manage.py (use for manage project)
      settings.py (configuration file of django project)
      urls.py (this is another configuration file. You can think of it as a mapping
                   between URLs and Python functions)

next open setting.py file and find bellow section

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

when you find this section then edit this section to

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "store",
        'USER': "root",
        'PASSWORD':"root",
    }
}

we will try to connect mysql thats why we have set database module name "django.db.backends.mysql" this is a class that are in django/db/backends and class name is mysql this will load when django server will run and also i have set database name ,username and password(this is password that you have given on mysql intalletion) this all mysql information

next you need to create database so open terminal and type

$mysql -uroot -p

next give your mysql password if you right password you will see mysql command prompt

next type this command

mysql>create database store

this command for create store database

Finally, we will tell Django to populate the configured database with tables.
Although we haven't created any tables for our data, Django requires several tables in the database for some of its features to function properly. Creating these tables is easy just follow and type this command in terminal and you will see your result:

first of all go to your django folder next store folder from your terminal

$cd django
$cd store

when you at store folder then type bellow command

$ python manage.py syncdb

this command for syncronized with database

If you have entered the above command and everything is correct, status messages will scroll on the screen indicating that the tables are being created. When prompted for the superuser account, enter your preferred username, email address and password. It is important to create a superuser account otherwise you won't be able to gain access to your initial webpage once you have created it. If, on the other hand, the database is mis-configured, an error message will be printed to help you troubleshoot the issue like bellow screenshot

command prompt syncdb

and finally you can launching the development server

go to store folder from terminal and type this command:

$ python manage.py runserver

this command for run your django server

Next, open your browser, and navigate to http://localhost:8000/. You should see a welcome message as in the image below:



welcome to django group now you will enjoy with your cocktail