Blogger Template by Blogcrowds.


  • Simple way to implement dynamic image upload_to path based on object.It is now possible for the upload_to parameter of the FileField or ImageField to be a callable, instead of a string. The callable is passed the current model instance and uploaded file name and must return a path.
class Books(models.Model):
class Collection(models.Model):
       def imagepath(instance,filename):
            val="Book_Media/" + str( + "/" + str(filename)
return val
  • imagepath is the callable (in this case a function). It simply gets the 'no' from the instance of Books and uses that in the upload path. Images will be uploaded to paths like: Book_Media/1/djano.jpg


Simple way to implement Ajax in Django with the help of Dojo toolkit.

  • Create a model for Book

class Book(models.Model):
name = models.CharField(max_length = 50)
author = models.CharField(max_length = 60)
year = models.IntegerField()
ref_no =models.IntegerField()

  • Create a ModelForm for 'Book' Models

  • Write a function for save the details of 'Book'

  • class BookForm(ModelForm):
        class Meta:
    def AddBook(request):
        if request.method == 'POST':
            if form.is_valid():
       save Book
                return HttpResponse ("1")#if Book object stored, return confirmation.
                return HttpResponse ("Please check the form data.")# if form validation failed
            return render_to_response("Register.html",{'Form':form})

    3. Register.html

    • Import Dojo necessary packages to your html file

    • Import Ajax.js where we are going to write the ajax function.

    • Div 'result' for show the response(from after the form submission.

    <script type="text/javascript" src="/path_to_dojo/dojo-release-1.2.0/dojo/dojo.js" djConfig="parseOnLoad:true"></script>
    <script type="text/javascript" src="ajax.js" ></script>
    <div id=”result”></div>
    <div id=”FormDiv”>
    <form id="AddBook">
    <input type="submit" onclick="return ValidateBook();">


    • Write a function named as ValidateBook

    • Declare a variable 'kw'

    • Variable 'data' contains the response .

    • If the Book details storeded in database, then will return '1' for confirmation

    • If Book details failed to validate , then error response will return.

    function ValidateBook()
    var kw = {
    form: dojo.byId("AddBook"),
    url: "/book/add/",
    load: function(data){
    if (data==1)
    dojo.byId("result").innerHTML="Book details has been registered successfully. ;

    dojo.byId("test").innerHTML = data;
    error: function(data){
    console.debug("An error occurred: ", data);
    timeout: 5000,
    form: "AddBook"
    dojo.xhrPost(kw); //Servlet get argement with doPost


Ubuntu is a great OS for use in both virtualisation hosts and in guest virtual machines and software appliances. Virtualization simply means the running of another OS within a host OS, through the usage of a special "hypervisor" application which handles everything about how the guest OS operates within (and with) the host system

Disable Apparmor:

/etc/init.d/apparmor stop
update-rc.d -f apparmor remove

Install XEN:

  • apt-get install ubuntu-xen-server

  • After installation of xen you should edit xorg.conf file.

  • Update xorg configuration.vim /etc/X11/ xorg.conf
    Your original xorg.conf files looks

    Section "Device"
    Identifier "Configured Video Device"

    Now add the following line in xorg.conf

    Section "Device"
    Identifier "Configured Video Device"
    Driver "i810"

  • Note: Here i810 refers to graphics chipset.So check out your system graphics chipset.

Download 2.6.24-16-xen kernel To avoid network problem:

  • wget

Replace the Ubuntu 2.6.24-16-xen kernel:

  • dpkg -i linux-image-2.6.24-16-xen_2.6.24-16.30zng1_i386.deb

  • Reboot your system

Move tls file:

  • mv /lib/tls /lib/tls.disabled

Modify Modules:

  • Add the line in vim /etc/modules

    loop max_loop=64

Directory for XEN:

  • mkdir /home/xen

Modify xen-tools.conf:

  • vim /etc/xen-tools/xen-tools.conf

install-method = debootstrap # method will change with respect to type of OS
dir = /home/xen
dhcp = 1
dist = hardy # Type of guest os
passwd = 1
mirror =

  • Reboot your system

Now Run

  • jayapal@kcs:~$ uname -r

Create Guest OS:

  • jayapal@kcs:~$ xen-create-image --hostname=Guestos --ide --passwd

  • Note: You can give size, swap, Network settings, etc... to override settings in xen-tools.conf.

  • For more details jayapal@kcs:~$ man xen-create-image

  • After creating image file,Terminal will show message as :

    Logfile produced at:


  • vim /etc/xen/Guestos.cfg

kernel = '/boot/vmlinuz-2.6.24-16-xen'
ramdisk = '/boot/initrd.img-2.6.24-16-xen'
memory = '128'
vcpus = '2' #For dual-core CPU
root = '/dev/hda2 ro'
disk = [
vif = [ 'ip= mac=00:16:3E:C9:C2:6C' ]

To start the virtual machine:

  • xm create /etc/xen/Guestos.cfg
    Using config file "/etc/xen/Guestos.cfg".
    Started domain Guestos

  • xm console Guestos
    Guestos started and it will prompt for user login.

  • To Stop the virtual machine:
    xm shutdown Guestos

  • for more command see xm man

For Centos:

  • Download initrd.img and vmlinuz, then move in to /boot/ directory


  • Mirror


Newer Posts Older Posts Home