SlideShare a Scribd company logo
1 of 37
Download to read offline
Hands on to django




       November 15, 2009




()        Hands on to django   November 15, 2009   1 / 36
disclaimer




    this is based on my brief experience in django
    a lot is from my job experience
    a lot of the code does not look this way, i just clean it up
    and cram a lot of space




          ()                   Hands on to django          November 15, 2009   2 / 36
the slide and code is on the web




the code is bitbucket.org
http://bitbucket.org/sweemeng/barcamp-malacca/

slide is on slideshare.net
http://www.slideshare.net/sweemenghacker/a-hands-on-guide-to-django




          ()                 Hands on to django      November 15, 2009   3 / 36
What is django




   Django is a Web framework
   Build on the python programming language




        ()                 Hands on to django   November 15, 2009   4 / 36
What you will need




You will need
    python, I use python 2.6, because ubuntu uses it
    a database, I use mysql
    python-mysql for mysql
    and thats pretty much everything




          ()                  Hands on to django       November 15, 2009   5 / 36
Lets start




To start a django project
The command on terminal
python django-admin startproject example

begin demo 1




          ()                  Hands on to django   November 15, 2009   6 / 36
A little setup Part 1


A few files is created form the command previously
File list
manage.py settings.py templates urls.py

Now we concern on settings.py
Before that create a database in mysql
create database
create database exampledb;




            ()                 Hands on to django   November 15, 2009   7 / 36
A little setup Part 2




DATABASE ENGINE = ’ mysql ’
DATABASE NAME = ’ exampledb ’
DATABASE USER = ’ r o o t ’
DATABASE PASSWORD = ’ r o o t ’




         ()              Hands on to django   November 15, 2009   8 / 36
Let start an app


    A django project is consist of multiple applications
    To start an app, use manage.py
start a django apps
python manage.py startapp exampleapp

    The newly create app folder should have
example content
 init .py models.py tests.py urls.py views.py




          ()                   Hands on to django          November 15, 2009   9 / 36
What ORM?


  django talk to database using ORM
  ORM == Object Relational Mapper
  It is used to model a database table into object
  start create one in exampleapp/models.py
  from d j a n g o . db i m p o r t m o d e l s
  # Create your models here .
  c l a s s Example ( m o d e l s . Model ) :
          name = m o d e l s . T e x t F i e l d ( )
          s c o r e = models . I n t e g e r F i e l d ( )

  Django models field also have field like email, and image




         ()                       Hands on to django         November 15, 2009   10 / 36
lets prepare our application


    before we can run our application
    a little setup


    INSTALLED APPS = (
        ’ django . c o n t r i b   . auth ’ ,
        ’ django . c o n t r i b   . contenttypes ’ ,
        ’ django . c o n t r i b   . sessions ’ ,
        ’ django . c o n t r i b   . sites ’ ,
        ’ exampleapp ’ ,
    )




          ()                   Hands on to django       November 15, 2009   11 / 36
setup redux




    now setting up the database
creating the table
python manage.py syncdb

    when prompt to create new superuser, just type yes
    and fill in the infor what ever you wanted




          ()                  Hands on to django         November 15, 2009   12 / 36
now to create a basic view
in exampleapps/views.py
from d j a n g o . h t t p i m p o r t H t t p R e s p o n s e
from d j a n g o . h t t p i m p o r t H t t p R e s p o n s e R e d i r e c t
from d j a n g o . s h o r t c u t s i m p o r t r e n d e r t o r e s p o n s e
# Create your views here .
from m o d e l s i m p o r t ∗
def example view ( request ) :
    i f r e q u e s t . method == ’POST ’ :
            d a t a = Example (
                             name = r e q u e s t . POST . g e t ( ’ p o s t i n g ’ ) ,
                             s c o r e = 0)
            data . save ()
    r e s = Example . o b j e c t s . a l l ( )
    r e t u r n r e n d e r t o r e s p o n s e ( ’ e x a m p l e / t e m p l a t e . html ’ ,
                                      { ’ res ’ : r e s })

             ()                       Hands on to django             November 15, 2009   13 / 36
add this extra views




def example like ( request , id ) :
    d a t a = Example . o b j e c t s . g e t ( i d=i d )
    data . s c o r e = data . s c o r e + 1
    data . save ()
    r e t u r n H ttp Re sp ons eR ed ire ct ( ’/ example / ’)




          ()                   Hands on to django       November 15, 2009   14 / 36
add this extra views




def example hate ( request , id ) :
    d a t a = Example . o b j e c t s . g e t ( i d=i d )
    data . s c o r e = data . s c o r e − 1
    data . save ()
    r e t u r n H ttp Re sp ons eR ed ire ct ( ’/ example / ’)




          ()                   Hands on to django       November 15, 2009   15 / 36
now create template

<html>
<head>
</head>
<body>
<b r/><a h r e f =’/ e x a m p l e / l o g o u t /’> l o g o u t </a>
<form method =’ p o s t ’ a c t i o n =’/ e x a m p l e /’>
 F i l l in your s t a t u s
<b r/>< t e x t a r e a name=’ p o s t i n g ’></ t e x t a r e a >
<b r/><i n p u t t y p e =’ submit ’ v a l u e =’ submit ’/>
</form>
<b r/>
{% f o r d i n r e s %}
        {{ d . name}} {{ d . s c o r e }}< b r/>
        <a h r e f =”/ e x a m p l e / l i k e /{{ d . i d }}/”> l i k e </a> <a
        h r e f =”/ e x a m p l e / h a t e /{{ d . i d }}/”> h at e </a><b r/>
{% e n d f o r %}
</body> ()                                Hands on to django          November 15, 2009   16 / 36
almost there


first create urls.py in exampleapps


from d j a n g o . c o n f . u r l s . d e f a u l t s i m p o r t ∗
from v i e w s i m p o r t ∗
urlpatterns = patterns ( ’ ’ ,
                     ( r ’ˆ $ ’ , example view ) ,
                     ( r ’ ˆ l i k e / (  d+)/$ ’ , e x a m p l e l i k e ) ,
                     ( r ’ ˆ h a t e / (  d+)/$ ’ , e x a m p l e h a t e ) ,
                     )




            ()                        Hands on to django             November 15, 2009   17 / 36
still going

and add a new entry in the main urls.py


from d j a n g o . c o n f . u r l s . d e f a u l t s i m p o r t ∗

# Uncomment t h e n e x t two l i n e s t o e n a b l e t h e admin :
#from d j a n g o . c o n t r i b i m p o r t admin
#admin . a u t o d i s c o v e r ( )

urlpatterns = patterns ( ’ ’ ,
    ( r ’ ˆ example / ’ , i n c l u d e ( ’ exampleapp . u r l s ’ ) ) ,
    ( r ’ ˆ admin / ’ , i n c l u d e ( admin . s i t e . u r l s ) ) ,
)




            ()                        Hands on to django               November 15, 2009   18 / 36
now run the program




run the internal server
python manage.py runserver

and test the app by pointing your browser
point browser to this address
localhost:8000/examples/




          ()                    Hands on to django   November 15, 2009   19 / 36
Now to add some login




   before we continue
   django have many application that make live easier
   here we first look at the authentication framework




        ()                   Hands on to django         November 15, 2009   20 / 36
first we import some modules




from   django .   contrib   . auth . d e c o r a t o r s import l o g i n r e q u i
from   django .   contrib   . auth import a u t h e n t i c a t e
from   django .   contrib   . auth import l o g i n
from   django .   contrib   . auth import l o g o u t
from   django .   contrib   . auth . models import User
BTW the apps is installed by default




          ()                    Hands on to django          November 15, 2009   21 / 36
lets enable registration.
   The user registration just need the username,password,email
   here is the view

   def example register ( request ) :
       i f r e q u e s t . method == ’POST ’ :
             username = r e q u e s t . POST . g e t ( ’ username ’ )
             p a s s w o r d = r e q u e s t . POST . g e t ( ’ p as sw or d ’ )
             e m a i l = r e q u e s t . POST . g e t ( ’ e m a i l ’ )
             u s e r = U s e r . o b j e c t s . c r e a t e u s e r ( username ,
                                                             email , password )
             user . save ()
             return HttpResponseRedirect (
                                   ’/ example / l o g i n / ’)
       else :
             return render to response (
                                 ’ e x a m p l e / r e g i s t e r . html ’ , { } )
         ()                      Hands on to django           November 15, 2009   22 / 36
the templates

def example register ( request ) :
    i f r e q u e s t . method == ’POST ’ :
          username = r e q u e s t . POST . g e t ( ’ username ’ )
          p a s s w o r d = r e q u e s t . POST . g e t ( ’ p as sw or d ’ )
          e m a i l = r e q u e s t . POST . g e t ( ’ e m a i l ’ )
          u s e r = U s e r . o b j e c t s . c r e a t e u s e r ( username
                                                              , email
                                                              , password )
          user . save ()
          return HttpResponseRedirect (
                                                    ’/ example / l o g i n / ’)
    else :
          return render to response (
                                ’ e x a m p l e / r e g i s t e r . html ’ , { } )

            ()                      Hands on to django            November 15, 2009   23 / 36
lets login




def example login ( request ) :
    i f r e q u e s t . method == ’POST ’ :
          u s e r n a m e = r e q u e s t . POST . g e t ( ’ username ’ )
          p a s s w o r d = r e q u e s t . POST . g e t ( ’ p as sw ord ’ )
          u s e r = a u t h e n t i c a t e ( username = u s e r n a m e ,
                              password = password )
         #c o n t i n u e d n e x t page




           ()                     Hands on to django         November 15, 2009   24 / 36
continued
        #from p r e v i o u s page
         i f u s e r i s n o t None :
               i f user . i s a c t i v e :
                     login ( request , user )
                     return HttpResponseRedirect (
                                                    ’/ example / ’)
               else :
                     return HttpResponseRedirect (
                                                  ’/ example / l o g i n / ’)
         else :
               return HttpResponseRedirect (
                                                  ’/ example / l o g i n / ’)
    else :
         return render to response (
                                         ’ e x a m p l e / l o g i n . html ’ , { } )

         ()                       Hands on to django            November 15, 2009   25 / 36
and the login page

<html>
<head>
</head>
<body>
<form a c t i o n =’/ e x a m p l e / l o g i n / ’ method =’ p o s t ’>
<b r/>< l a b e l >username :</ l a b e l >
<i n p u t t y p e =’ t e x t ’ name=’ username ’/>
<b r/>< l a b e l >p a s s w o r d :</ l a b e l >
<i n p u t t y p e =’ passwo rd ’ name=’ pa ss wo rd ’/>
<b r/><i n p u t t y p e =’ submit ’ v a l u e =’ submit ’/>
</form>

</body>
</html>

            ()                     Hands on to django          November 15, 2009   26 / 36
logout




def example logout ( request ) :
    logout ( request )
    return HttpResponseRedirect (
             ’/ example / l o g i n / ’)




         ()                Hands on to django   November 15, 2009   27 / 36
now to make it works




urlpatterns = patterns ( ’ ’ ,
             ( r ’ˆ $ ’ , example view ) ,
             ( r ’ ˆ l o g i n /$ ’ , e x a m p l e l o g i n ) ,
             ( r ’ ˆ r e g i s t e r /$ ’ , e x a m p l e r e g i s t e r ) ,
             ( r ’ ˆ l o g o u t /$ ’ , e x a m p l e l o g o u t ) ,
             ( r ’ ˆ l i k e / (  d+)/$ ’ , e x a m p l e l i k e ) ,
             ( r ’ ˆ h a t e / (  d+)/$ ’ , e x a m p l e h a t e ) ,
             )




           ()                       Hands on to django           November 15, 2009   28 / 36
to apply it to our apps




    to apply login needed for our views
    just add a line called @login required
    it will force a login




          ()                   Hands on to django   November 15, 2009   29 / 36
a little setup again




add the following line to settings.py


LOGIN URL = ’ / e x a m p l e / l o g i n / ’
LOGOUT URL = ’ / e x a m p l e / l o g i n / ’




           ()                     Hands on to django   November 15, 2009   30 / 36
the best part of django




    admin page is free on django
    meaning you can just use enable it




         ()                   Hands on to django   November 15, 2009   31 / 36
still going

uncomment admin stuff in in the main urls.py


from d j a n g o . c o n f . u r l s . d e f a u l t s i m p o r t ∗


from d j a n g o . c o n t r i b i m p o r t admin
admin . a u t o d i s c o v e r ( )

urlpatterns = patterns ( ’ ’ ,
    ( r ’ ˆ example / ’ , i n c l u d e ( ’ exampleapp . u r l s ’ ) ) ,
      ( r ’ ˆ admin / ’ , i n c l u d e ( admin . s i t e . u r l s ) ) ,
)




            ()                        Hands on to django               November 15, 2009   32 / 36
now to create admin.py




from d j a n g o . c o n t r i b i m p o r t admin
from m o d e l s i m p o r t ∗
admin . s i t e . r e g i s t e r ( Example )




           ()                     Hands on to django   November 15, 2009   33 / 36
install the admin apps



INSTALLED APPS = (
    ’ django . c o n t r i b   . auth ’ ,
    ’ django . c o n t r i b   . contenttypes ’ ,
    ’ django . c o n t r i b   . sessions ’ ,
    ’ django . c o n t r i b   . sites ’ ,
    ’ django . c o n t r i b   . admin ’ ,
    ’ exampleapp ’ ,
)




           ()                     Hands on to django   November 15, 2009   34 / 36
now to finish up




run syncdb
python manage.py syncdb




         ()               Hands on to django   November 15, 2009   35 / 36
in the end




    this is just a demo on a few thing on django
    django offer a lot more
    builtin feed syndication,commenting,tagging,GIS




         ()                   Hands on to django      November 15, 2009   36 / 36
that’s all folks




So Long And Thanks For All The Fish




         ()                 Hands on to django   November 15, 2009   37 / 36

More Related Content

What's hot

How To Think In Go
How To Think In GoHow To Think In Go
How To Think In Golestrrat
 
Testing TYPO3 Applications
Testing TYPO3 ApplicationsTesting TYPO3 Applications
Testing TYPO3 ApplicationsAndré Wuttig
 
Pulsar Architectural Patterns for CI/CD Automation and Self-Service
Pulsar Architectural Patterns for CI/CD Automation and Self-ServicePulsar Architectural Patterns for CI/CD Automation and Self-Service
Pulsar Architectural Patterns for CI/CD Automation and Self-ServiceDevin Bost
 
Functional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heavenFunctional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heavenPawel Szulc
 
Geb for Testing Your Grails Application GR8Conf India 2016
Geb for Testing Your Grails Application  GR8Conf India 2016Geb for Testing Your Grails Application  GR8Conf India 2016
Geb for Testing Your Grails Application GR8Conf India 2016Jacob Aae Mikkelsen
 
Semantic Web & TYPO3
Semantic Web & TYPO3Semantic Web & TYPO3
Semantic Web & TYPO3André Wuttig
 
JavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayJavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayRobert Nyman
 
Architecting for PHP5 - Why "Runs on PHP5" is not "Written for PHP5"
Architecting for PHP5 - Why "Runs on PHP5" is not "Written for PHP5"Architecting for PHP5 - Why "Runs on PHP5" is not "Written for PHP5"
Architecting for PHP5 - Why "Runs on PHP5" is not "Written for PHP5"ZendCon
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Andrew Shitov
 
Beginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleBeginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleAri Lerner
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival GuideGiordano Scalzo
 
JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJosé Paumard
 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindiaComplaints
 
Real world gobbledygook
Real world gobbledygookReal world gobbledygook
Real world gobbledygookPawel Szulc
 

What's hot (20)

Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
 
How To Think In Go
How To Think In GoHow To Think In Go
How To Think In Go
 
Testing TYPO3 Applications
Testing TYPO3 ApplicationsTesting TYPO3 Applications
Testing TYPO3 Applications
 
Pulsar Architectural Patterns for CI/CD Automation and Self-Service
Pulsar Architectural Patterns for CI/CD Automation and Self-ServicePulsar Architectural Patterns for CI/CD Automation and Self-Service
Pulsar Architectural Patterns for CI/CD Automation and Self-Service
 
Functional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heavenFunctional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heaven
 
Geb for Testing Your Grails Application GR8Conf India 2016
Geb for Testing Your Grails Application  GR8Conf India 2016Geb for Testing Your Grails Application  GR8Conf India 2016
Geb for Testing Your Grails Application GR8Conf India 2016
 
Semantic Web & TYPO3
Semantic Web & TYPO3Semantic Web & TYPO3
Semantic Web & TYPO3
 
JavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDayJavaScript - Like a Box of Chocolates - jsDay
JavaScript - Like a Box of Chocolates - jsDay
 
Inc
IncInc
Inc
 
Architecting for PHP5 - Why "Runs on PHP5" is not "Written for PHP5"
Architecting for PHP5 - Why "Runs on PHP5" is not "Written for PHP5"Architecting for PHP5 - Why "Runs on PHP5" is not "Written for PHP5"
Architecting for PHP5 - Why "Runs on PHP5" is not "Written for PHP5"
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 
groovy & grails - lecture 2
groovy & grails - lecture 2groovy & grails - lecture 2
groovy & grails - lecture 2
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
Lettering js
Lettering jsLettering js
Lettering js
 
Beginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleBeginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at Google
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easy
 
01c shell
01c shell01c shell
01c shell
 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on php
 
Real world gobbledygook
Real world gobbledygookReal world gobbledygook
Real world gobbledygook
 

Similar to a hands on guide to django

Building Pluggable Web Applications using Django
Building Pluggable Web Applications using DjangoBuilding Pluggable Web Applications using Django
Building Pluggable Web Applications using DjangoLakshman Prasad
 
djangoic approach to implement common web development paradigms
djangoic approach to implement common web development paradigmsdjangoic approach to implement common web development paradigms
djangoic approach to implement common web development paradigmsLakshman Prasad
 
Faster! Faster! Accelerate your business with blazing prototypes
Faster! Faster! Accelerate your business with blazing prototypesFaster! Faster! Accelerate your business with blazing prototypes
Faster! Faster! Accelerate your business with blazing prototypesOSCON Byrum
 
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
Y o u r  N a m e   L S P  2 0 0 - 3 2 0  ( c o u r s e  I .docxY o u r  N a m e   L S P  2 0 0 - 3 2 0  ( c o u r s e  I .docx
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docxherminaprocter
 
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
Y o u r  N a m e   L S P  2 0 0 - 3 2 0  ( c o u r s e  I .docxY o u r  N a m e   L S P  2 0 0 - 3 2 0  ( c o u r s e  I .docx
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docxodiliagilby
 
Web Development Paradigms and djangoic approach to deal with them
Web Development Paradigms and djangoic approach to deal with themWeb Development Paradigms and djangoic approach to deal with them
Web Development Paradigms and djangoic approach to deal with themLakshman Prasad
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosIgor Sobreira
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers ToolboxStefan
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimMir Nazim
 
WordPress in 30 minutes
WordPress in 30 minutesWordPress in 30 minutes
WordPress in 30 minutesOwen Winkler
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1MicroPyramid .
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talkdtdannen
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
Introducing Command Line Applications with Ruby
Introducing Command Line Applications with RubyIntroducing Command Line Applications with Ruby
Introducing Command Line Applications with RubyNikhil Mungel
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Hermann Hueck
 

Similar to a hands on guide to django (20)

Building Pluggable Web Applications using Django
Building Pluggable Web Applications using DjangoBuilding Pluggable Web Applications using Django
Building Pluggable Web Applications using Django
 
djangoic approach to implement common web development paradigms
djangoic approach to implement common web development paradigmsdjangoic approach to implement common web development paradigms
djangoic approach to implement common web development paradigms
 
Django
DjangoDjango
Django
 
Faster! Faster! Accelerate your business with blazing prototypes
Faster! Faster! Accelerate your business with blazing prototypesFaster! Faster! Accelerate your business with blazing prototypes
Faster! Faster! Accelerate your business with blazing prototypes
 
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
Y o u r  N a m e   L S P  2 0 0 - 3 2 0  ( c o u r s e  I .docxY o u r  N a m e   L S P  2 0 0 - 3 2 0  ( c o u r s e  I .docx
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
 
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
Y o u r  N a m e   L S P  2 0 0 - 3 2 0  ( c o u r s e  I .docxY o u r  N a m e   L S P  2 0 0 - 3 2 0  ( c o u r s e  I .docx
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
 
pyscript_django.pdf
pyscript_django.pdfpyscript_django.pdf
pyscript_django.pdf
 
Web Development Paradigms and djangoic approach to deal with them
Web Development Paradigms and djangoic approach to deal with themWeb Development Paradigms and djangoic approach to deal with them
Web Development Paradigms and djangoic approach to deal with them
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers Toolbox
 
Django
DjangoDjango
Django
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
 
WordPress in 30 minutes
WordPress in 30 minutesWordPress in 30 minutes
WordPress in 30 minutes
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Easy R
Easy REasy R
Easy R
 
Introducing Command Line Applications with Ruby
Introducing Command Line Applications with RubyIntroducing Command Line Applications with Ruby
Introducing Command Line Applications with Ruby
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
 

More from swee meng ng

Civic tech in malaysia and beyond
Civic tech in malaysia and beyondCivic tech in malaysia and beyond
Civic tech in malaysia and beyondswee meng ng
 
High Level View of Civic Tech
High Level View of Civic TechHigh Level View of Civic Tech
High Level View of Civic Techswee meng ng
 
How we use Bottle and Elasticsearch
How we use Bottle and ElasticsearchHow we use Bottle and Elasticsearch
How we use Bottle and Elasticsearchswee meng ng
 
Build website in_django
Build website in_django Build website in_django
Build website in_django swee meng ng
 
introduction to linux desktop draft 5
introduction to linux desktop draft 5introduction to linux desktop draft 5
introduction to linux desktop draft 5swee meng ng
 

More from swee meng ng (9)

Civic tech in malaysia and beyond
Civic tech in malaysia and beyondCivic tech in malaysia and beyond
Civic tech in malaysia and beyond
 
High Level View of Civic Tech
High Level View of Civic TechHigh Level View of Civic Tech
High Level View of Civic Tech
 
Python on pi
Python on piPython on pi
Python on pi
 
Lvl.up
Lvl.upLvl.up
Lvl.up
 
Data prospecting
Data prospectingData prospecting
Data prospecting
 
How we use Bottle and Elasticsearch
How we use Bottle and ElasticsearchHow we use Bottle and Elasticsearch
How we use Bottle and Elasticsearch
 
Hackerspacekl
HackerspaceklHackerspacekl
Hackerspacekl
 
Build website in_django
Build website in_django Build website in_django
Build website in_django
 
introduction to linux desktop draft 5
introduction to linux desktop draft 5introduction to linux desktop draft 5
introduction to linux desktop draft 5
 

Recently uploaded

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Recently uploaded (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

a hands on guide to django

  • 1. Hands on to django November 15, 2009 () Hands on to django November 15, 2009 1 / 36
  • 2. disclaimer this is based on my brief experience in django a lot is from my job experience a lot of the code does not look this way, i just clean it up and cram a lot of space () Hands on to django November 15, 2009 2 / 36
  • 3. the slide and code is on the web the code is bitbucket.org http://bitbucket.org/sweemeng/barcamp-malacca/ slide is on slideshare.net http://www.slideshare.net/sweemenghacker/a-hands-on-guide-to-django () Hands on to django November 15, 2009 3 / 36
  • 4. What is django Django is a Web framework Build on the python programming language () Hands on to django November 15, 2009 4 / 36
  • 5. What you will need You will need python, I use python 2.6, because ubuntu uses it a database, I use mysql python-mysql for mysql and thats pretty much everything () Hands on to django November 15, 2009 5 / 36
  • 6. Lets start To start a django project The command on terminal python django-admin startproject example begin demo 1 () Hands on to django November 15, 2009 6 / 36
  • 7. A little setup Part 1 A few files is created form the command previously File list manage.py settings.py templates urls.py Now we concern on settings.py Before that create a database in mysql create database create database exampledb; () Hands on to django November 15, 2009 7 / 36
  • 8. A little setup Part 2 DATABASE ENGINE = ’ mysql ’ DATABASE NAME = ’ exampledb ’ DATABASE USER = ’ r o o t ’ DATABASE PASSWORD = ’ r o o t ’ () Hands on to django November 15, 2009 8 / 36
  • 9. Let start an app A django project is consist of multiple applications To start an app, use manage.py start a django apps python manage.py startapp exampleapp The newly create app folder should have example content init .py models.py tests.py urls.py views.py () Hands on to django November 15, 2009 9 / 36
  • 10. What ORM? django talk to database using ORM ORM == Object Relational Mapper It is used to model a database table into object start create one in exampleapp/models.py from d j a n g o . db i m p o r t m o d e l s # Create your models here . c l a s s Example ( m o d e l s . Model ) : name = m o d e l s . T e x t F i e l d ( ) s c o r e = models . I n t e g e r F i e l d ( ) Django models field also have field like email, and image () Hands on to django November 15, 2009 10 / 36
  • 11. lets prepare our application before we can run our application a little setup INSTALLED APPS = ( ’ django . c o n t r i b . auth ’ , ’ django . c o n t r i b . contenttypes ’ , ’ django . c o n t r i b . sessions ’ , ’ django . c o n t r i b . sites ’ , ’ exampleapp ’ , ) () Hands on to django November 15, 2009 11 / 36
  • 12. setup redux now setting up the database creating the table python manage.py syncdb when prompt to create new superuser, just type yes and fill in the infor what ever you wanted () Hands on to django November 15, 2009 12 / 36
  • 13. now to create a basic view in exampleapps/views.py from d j a n g o . h t t p i m p o r t H t t p R e s p o n s e from d j a n g o . h t t p i m p o r t H t t p R e s p o n s e R e d i r e c t from d j a n g o . s h o r t c u t s i m p o r t r e n d e r t o r e s p o n s e # Create your views here . from m o d e l s i m p o r t ∗ def example view ( request ) : i f r e q u e s t . method == ’POST ’ : d a t a = Example ( name = r e q u e s t . POST . g e t ( ’ p o s t i n g ’ ) , s c o r e = 0) data . save () r e s = Example . o b j e c t s . a l l ( ) r e t u r n r e n d e r t o r e s p o n s e ( ’ e x a m p l e / t e m p l a t e . html ’ , { ’ res ’ : r e s }) () Hands on to django November 15, 2009 13 / 36
  • 14. add this extra views def example like ( request , id ) : d a t a = Example . o b j e c t s . g e t ( i d=i d ) data . s c o r e = data . s c o r e + 1 data . save () r e t u r n H ttp Re sp ons eR ed ire ct ( ’/ example / ’) () Hands on to django November 15, 2009 14 / 36
  • 15. add this extra views def example hate ( request , id ) : d a t a = Example . o b j e c t s . g e t ( i d=i d ) data . s c o r e = data . s c o r e − 1 data . save () r e t u r n H ttp Re sp ons eR ed ire ct ( ’/ example / ’) () Hands on to django November 15, 2009 15 / 36
  • 16. now create template <html> <head> </head> <body> <b r/><a h r e f =’/ e x a m p l e / l o g o u t /’> l o g o u t </a> <form method =’ p o s t ’ a c t i o n =’/ e x a m p l e /’> F i l l in your s t a t u s <b r/>< t e x t a r e a name=’ p o s t i n g ’></ t e x t a r e a > <b r/><i n p u t t y p e =’ submit ’ v a l u e =’ submit ’/> </form> <b r/> {% f o r d i n r e s %} {{ d . name}} {{ d . s c o r e }}< b r/> <a h r e f =”/ e x a m p l e / l i k e /{{ d . i d }}/”> l i k e </a> <a h r e f =”/ e x a m p l e / h a t e /{{ d . i d }}/”> h at e </a><b r/> {% e n d f o r %} </body> () Hands on to django November 15, 2009 16 / 36
  • 17. almost there first create urls.py in exampleapps from d j a n g o . c o n f . u r l s . d e f a u l t s i m p o r t ∗ from v i e w s i m p o r t ∗ urlpatterns = patterns ( ’ ’ , ( r ’ˆ $ ’ , example view ) , ( r ’ ˆ l i k e / ( d+)/$ ’ , e x a m p l e l i k e ) , ( r ’ ˆ h a t e / ( d+)/$ ’ , e x a m p l e h a t e ) , ) () Hands on to django November 15, 2009 17 / 36
  • 18. still going and add a new entry in the main urls.py from d j a n g o . c o n f . u r l s . d e f a u l t s i m p o r t ∗ # Uncomment t h e n e x t two l i n e s t o e n a b l e t h e admin : #from d j a n g o . c o n t r i b i m p o r t admin #admin . a u t o d i s c o v e r ( ) urlpatterns = patterns ( ’ ’ , ( r ’ ˆ example / ’ , i n c l u d e ( ’ exampleapp . u r l s ’ ) ) , ( r ’ ˆ admin / ’ , i n c l u d e ( admin . s i t e . u r l s ) ) , ) () Hands on to django November 15, 2009 18 / 36
  • 19. now run the program run the internal server python manage.py runserver and test the app by pointing your browser point browser to this address localhost:8000/examples/ () Hands on to django November 15, 2009 19 / 36
  • 20. Now to add some login before we continue django have many application that make live easier here we first look at the authentication framework () Hands on to django November 15, 2009 20 / 36
  • 21. first we import some modules from django . contrib . auth . d e c o r a t o r s import l o g i n r e q u i from django . contrib . auth import a u t h e n t i c a t e from django . contrib . auth import l o g i n from django . contrib . auth import l o g o u t from django . contrib . auth . models import User BTW the apps is installed by default () Hands on to django November 15, 2009 21 / 36
  • 22. lets enable registration. The user registration just need the username,password,email here is the view def example register ( request ) : i f r e q u e s t . method == ’POST ’ : username = r e q u e s t . POST . g e t ( ’ username ’ ) p a s s w o r d = r e q u e s t . POST . g e t ( ’ p as sw or d ’ ) e m a i l = r e q u e s t . POST . g e t ( ’ e m a i l ’ ) u s e r = U s e r . o b j e c t s . c r e a t e u s e r ( username , email , password ) user . save () return HttpResponseRedirect ( ’/ example / l o g i n / ’) else : return render to response ( ’ e x a m p l e / r e g i s t e r . html ’ , { } ) () Hands on to django November 15, 2009 22 / 36
  • 23. the templates def example register ( request ) : i f r e q u e s t . method == ’POST ’ : username = r e q u e s t . POST . g e t ( ’ username ’ ) p a s s w o r d = r e q u e s t . POST . g e t ( ’ p as sw or d ’ ) e m a i l = r e q u e s t . POST . g e t ( ’ e m a i l ’ ) u s e r = U s e r . o b j e c t s . c r e a t e u s e r ( username , email , password ) user . save () return HttpResponseRedirect ( ’/ example / l o g i n / ’) else : return render to response ( ’ e x a m p l e / r e g i s t e r . html ’ , { } ) () Hands on to django November 15, 2009 23 / 36
  • 24. lets login def example login ( request ) : i f r e q u e s t . method == ’POST ’ : u s e r n a m e = r e q u e s t . POST . g e t ( ’ username ’ ) p a s s w o r d = r e q u e s t . POST . g e t ( ’ p as sw ord ’ ) u s e r = a u t h e n t i c a t e ( username = u s e r n a m e , password = password ) #c o n t i n u e d n e x t page () Hands on to django November 15, 2009 24 / 36
  • 25. continued #from p r e v i o u s page i f u s e r i s n o t None : i f user . i s a c t i v e : login ( request , user ) return HttpResponseRedirect ( ’/ example / ’) else : return HttpResponseRedirect ( ’/ example / l o g i n / ’) else : return HttpResponseRedirect ( ’/ example / l o g i n / ’) else : return render to response ( ’ e x a m p l e / l o g i n . html ’ , { } ) () Hands on to django November 15, 2009 25 / 36
  • 26. and the login page <html> <head> </head> <body> <form a c t i o n =’/ e x a m p l e / l o g i n / ’ method =’ p o s t ’> <b r/>< l a b e l >username :</ l a b e l > <i n p u t t y p e =’ t e x t ’ name=’ username ’/> <b r/>< l a b e l >p a s s w o r d :</ l a b e l > <i n p u t t y p e =’ passwo rd ’ name=’ pa ss wo rd ’/> <b r/><i n p u t t y p e =’ submit ’ v a l u e =’ submit ’/> </form> </body> </html> () Hands on to django November 15, 2009 26 / 36
  • 27. logout def example logout ( request ) : logout ( request ) return HttpResponseRedirect ( ’/ example / l o g i n / ’) () Hands on to django November 15, 2009 27 / 36
  • 28. now to make it works urlpatterns = patterns ( ’ ’ , ( r ’ˆ $ ’ , example view ) , ( r ’ ˆ l o g i n /$ ’ , e x a m p l e l o g i n ) , ( r ’ ˆ r e g i s t e r /$ ’ , e x a m p l e r e g i s t e r ) , ( r ’ ˆ l o g o u t /$ ’ , e x a m p l e l o g o u t ) , ( r ’ ˆ l i k e / ( d+)/$ ’ , e x a m p l e l i k e ) , ( r ’ ˆ h a t e / ( d+)/$ ’ , e x a m p l e h a t e ) , ) () Hands on to django November 15, 2009 28 / 36
  • 29. to apply it to our apps to apply login needed for our views just add a line called @login required it will force a login () Hands on to django November 15, 2009 29 / 36
  • 30. a little setup again add the following line to settings.py LOGIN URL = ’ / e x a m p l e / l o g i n / ’ LOGOUT URL = ’ / e x a m p l e / l o g i n / ’ () Hands on to django November 15, 2009 30 / 36
  • 31. the best part of django admin page is free on django meaning you can just use enable it () Hands on to django November 15, 2009 31 / 36
  • 32. still going uncomment admin stuff in in the main urls.py from d j a n g o . c o n f . u r l s . d e f a u l t s i m p o r t ∗ from d j a n g o . c o n t r i b i m p o r t admin admin . a u t o d i s c o v e r ( ) urlpatterns = patterns ( ’ ’ , ( r ’ ˆ example / ’ , i n c l u d e ( ’ exampleapp . u r l s ’ ) ) , ( r ’ ˆ admin / ’ , i n c l u d e ( admin . s i t e . u r l s ) ) , ) () Hands on to django November 15, 2009 32 / 36
  • 33. now to create admin.py from d j a n g o . c o n t r i b i m p o r t admin from m o d e l s i m p o r t ∗ admin . s i t e . r e g i s t e r ( Example ) () Hands on to django November 15, 2009 33 / 36
  • 34. install the admin apps INSTALLED APPS = ( ’ django . c o n t r i b . auth ’ , ’ django . c o n t r i b . contenttypes ’ , ’ django . c o n t r i b . sessions ’ , ’ django . c o n t r i b . sites ’ , ’ django . c o n t r i b . admin ’ , ’ exampleapp ’ , ) () Hands on to django November 15, 2009 34 / 36
  • 35. now to finish up run syncdb python manage.py syncdb () Hands on to django November 15, 2009 35 / 36
  • 36. in the end this is just a demo on a few thing on django django offer a lot more builtin feed syndication,commenting,tagging,GIS () Hands on to django November 15, 2009 36 / 36
  • 37. that’s all folks So Long And Thanks For All The Fish () Hands on to django November 15, 2009 37 / 36