How to Create a Django Project and App

Creating Django Project
Goto Terminal
Activate virtual environment *
$ django-admin.py startproject <project_name>

 

eg:- django-admin.py startproject myproject

This will create folder stricture like the bellow

 

How to run Django project

$ python manage.py runserver

How to Create an App

$ python manage.py startapp <app_name>

eg:-

$ python manage.py startapp myapp

This will create folder stricture like the bellow

How to implement model

add model details in models.py  (eg:- /myproject/myapp/models.py)

class Person(models.Model):
name = models.CharField(max_length=200)
adderess = models.TextField()
reg_date = models.DateTimeField(‘date registerd’)

def __str__(self):
return self.name

 

in the above example Person will be table name and all the variables inside the class will be the table field name (name, adderss,reg_date), by default django will create sqlite datablse (default database settings in settings.py)

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.sqlite3’,
‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’),
}
}

 

ref:-https://docs.djangoproject.com/en/dev/topics/db/models/

 

$ python manage.py sql polls

$ python manage.py syncdb

$ python manage.py runserver

  Like
Author: bm on July 8, 2014
Category: Python Django

Your comment:

Your Name

Comment:




Last articles