Learn Django

Today I start the learning of django Framework.

There is simple instructions for creating the application in Django .

  • django-admin.py startproject __NAME OF PROJECT__

Now you see some files in this folder like:- manage.py

  • django-admin.py startapp __NAME OF APP__

Now You some file in your application folder. like:module.py, admin.py etc.

Now go in your project folder 

  • cd projectname/

Then run this command 

  • python manage.php  migration                                                //For migrate with database

Now Start the coding of application (i make simple signup application)

open you module.py file in application folder

Module.py

from django.db import models
from django.utils.encoding import smart_unicode

class SignUp(models.Model):
first_name = models.CharField(max_length=120,null=True,blank=True)
last_name=models.CharField(max_length=120,null=True,blank=True)
email=models.EmailField(null=False,blank=False)
timestamp=models.DateTimeField(auto_now_add=True,auto_now=False)
updated=models.DateTimeField(auto_now_add=False,auto_now=True)

def __unicode__(self):
return smart_unicode(self.first_name)

 Now Start the coding of Admin panel. With help of this your application is easy to add in django control panel.

Admin.py

from django.contrib import admin

from .models import SignUp

class SignUpAdmin(admin.ModelAdmin):
class Meta:
model=SignUp

admin.site.register(SignUp,SignUpAdmin)

How to run this application follow this simple instructions 

  1. cd project name
  2. python manage.py createsuperuser                                                  //enter the superuser name and password
  3. python manage.py syncdb                                                              //create new table

Set up Your application in django so update settings.py file

settings.py file in your application folder

cd /project_name/project_name/

vim settings.py

Set up your database

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'he',
'USER':'root',
'PASSWORD':'',
'HOST':'localhost',
'PORT':''
}
}


  Set up your application 

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'your application name', 
)

Now run these commands to your project 

Go in your project folder

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s