SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Django

     Szalai Ferenc
(szferi@wsbricks.com)
Bevezetés
“Django egy magas szintű Python
    nyelven írt web alkalmazás
   keretrendszer, ami a gyors és
pragmatikus alkalmazás fejlesztést
            támogatja.”
Telepítés
előfeltétel: python, django forrás
(svn, tar.gz)
# cd django
# python setup.py install
http://www.djangoproject.com/documentation/install/
Alapfogalmak
●   Projekt
●   Alkalmazas
●   Model
●   View
●   Controller (URL)
●   Template
$ django-admin.py startproject supporter
$ ls -l supporter/

__init__.py
manage.py
settings.py
urls.py
$ python manage.py runserver
Validating models...
0 errors found

Django version 1.1 beta 1, using
settings 'supporter.settings'
Development server is running at
http://127.0.0.1:8000/
Quit the server with CONTROL-C.
settings.py
●   DATABASE_ENGINE
●   DATABASE_NAME
●   DATABASE_USER
●   DATABASE_PASSWORD
●   DATABASE_HOST
●   normál python modul
●   a saját konfig paramétereink legyenek
    nagybetűsek!
●   http://www.djangoproject.com/documentation/settings/
Alkalmazások
● logikai egység
● újrafelhasználható


● összetartozó model, view, url

  gyűjteménye
●   $ python manage.py startapp topic
$ ls topic/
__init__.py
models.py
tests.py
views.py
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'supporter.topic'
)
User




                                 Company




django.contrib.auth
                                  Topic
                                    Topic
       djangon.contrib.comment           Topic




             Comment              supporter.topic

                 Comment
Model
BEGIN;
CREATE TABLE "topic_topic" (
    "id" integer NOT NULL PRIMARY KEY,
    "author_id" integer NOT NULL,
    "type" varchar(1) NOT NULL,
    "title" varchar(128) NOT NULL,
    "content" text NOT NULL,
    "feeling" integer NOT NULL
)
;
COMMIT;
Az SQL csúnya
 A Python cool
from django.db import models
from django.contrib.auth.models import User

class Topic(models.Model):

    TOPIC_TYPES = (
        ('Q', 'Question'),
        ('I', 'Idea'),
        ('P', 'Problem'),
    )

    author = models.ForeignKey(User)
    type = models.CharField(max_length=1,
                          choices=TOPIC_TYPES)
    title = models.CharField(max_length=128)
    content = models.TextField()
    feeling = models.IntegerField()
    created = models.DateTimeField(auto_now_add=True)
$ python   manage.py validate
$ python   manage.py syncdb
Creating   table auth_permission
Creating   table auth_group
Creating   table auth_user
Creating   table auth_message
Creating   table django_content_type
Creating   table django_session
Creating   table django_site
Creating   table topic_topic

You just installed Django's auth system, which
means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'szferi'):
E-mail address: szferi@wsbricks.com
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for topic.Topic model
Model API
$ python manage.py shell
In [1]: from supporter.topic.models import Topic
In [2]: from django.contrib.auth.models import User
In [3]: u = User.objects.get(id=1)
In [4]: print u
szferi

In [5]: t = Topics.objects.create(author=u, type='Q',
title='test', content='nagybaj!', feeling=-1)
In [6]: print t
Topic object

In [7]: print t.title
test

In [8]: print Topic.objects.all()
[<Topic: Topic object>]
In [9]: ts = Topic.objects.filter(content__contains='baj')
In [10]: print ts[0].content
nagybaj!
class Topic(models.Model):
    ...

   def __unicode__(self):
       return self.title
$ python manage.py shell
In [1]: from supporter.topic.models import Topic
In [2]: print Topic.objects.all()
[<Topic: test>]
class Topic(models.Model):
    ...

   class Meta:
       ordering = ['created']
Relációk
from django.db import models
from django.contrib.auth.models import User

class Topic(models.Model):

    TOPIC_TYPES = (
        ('Q', 'Question'),
        ('I', 'Idea'),
        ('P', 'Problem'),
    )

    author = models.ForeignKey(User)
    type = models.CharField(max_length=1,
                          choices=TOPIC_TYPES)
    title = models.CharField(max_length=128)
    content = models.TextField()
    feeling = models.IntegerField()
    created = models.DateTimeField(auto_now_add=True)
$ python manage.py shell
In [2]: from django.contrib.auth.models import User
In [3]: u = User.objects.get(id=1)
In [4]: print u
szferi

In [5]: print u.topic_set.all()
[<Topic: test>]

In [6]: print u.topic_set.filter(type='Q')
[<Topic: test>]
Views
from django.http import HttpResponse

def index(request):
    return HttpResponse('Hello!')
intermezzó: URL
/customer/account/1/contacts/2/
from django.conf.urls.defaults import *
import views
urlpatterns = patterns('',
    (r'^$', views.index),
    (r'^(?P<topic>[0-9]*)/$', views.detail)
)
from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^topic/', include('supporter.topic.urls')),
)
Összetettebb View-k
from django.http import
HttpResponse
from supporter.topic.models
import Topic

def index(request):
    r = '<ul>'
    topics = Topic.objects.all()
    for t in topics:
        r += "<li>%s</li>" % 
                        t.title
    r += '</ul>'
    return HttpResponse(r)
intermezzó 2: Tempalte
<html>
<body>
<p>There is {{ topics|length }} topics</p>
<ul>
{% for t in topics %}
   <li>{{ t.title }}</li>
{% endfor %}
</ul>
</body>
</html>
Django Admin
from django.conf.urls.defaults import *
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^topic/', include('supporter.topic.urls')),
)
Formok
from models import Topic
from django.forms import ModelForm

class TopicForm(ModelForm):
    class Meta:
        model = Topic
        exclude = ('author', )
def add(request):
    from forms import TopicForm
    from django.http import HttpResponseRedirect
    from django.contrib.auth.models import User

    if request.method == 'POST':
        form = TopicForm(request.POST)
        if form.is_valid():
            topic = form.save(commit=False)
            topic.author = User.objects.get(id=1)
            topic.save()
            return HttpResponseRedirect('/')
    else:
        form = TopicForm()
    return render_to_response('add.html',
{'form': form })
<html>
<body>
<form method="post" action=".">
{{ form }}
<input type="submit" value="SAVE"
name="save"/>
</form>
</body>
</html>
Hova tovább, hovatovább
●   automatikus teszt
●   saját template tag és filter
●   session kezelés
●   authentikáció
●   cache
●   l10n, i18n
●   RSS/Atom
●   Generikus view-k
●   stb, stb.
Django - A gyors és pragmatikus webfejlesztés alapjai

Weitere ähnliche Inhalte

Was ist angesagt?

Jsoup Tutorial for Beginners - Javatpoint
Jsoup Tutorial for Beginners - JavatpointJsoup Tutorial for Beginners - Javatpoint
Jsoup Tutorial for Beginners - JavatpointJavaTpoint.Com
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)Simon Su
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
Web осень 2012 лекция 7
Web осень 2012 лекция 7Web осень 2012 лекция 7
Web осень 2012 лекция 7Technopark
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress sitereferences
 
Roman iovlev. Test UI with JDI - Selenium camp
Roman iovlev. Test UI with JDI - Selenium campRoman iovlev. Test UI with JDI - Selenium camp
Roman iovlev. Test UI with JDI - Selenium campРоман Иовлев
 
Introduction to jQuery - The basics
Introduction to jQuery - The basicsIntroduction to jQuery - The basics
Introduction to jQuery - The basicsMaher Hossain
 
PHP webboard
PHP webboardPHP webboard
PHP webboardtumetr1
 
yagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guideyagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guideMert Can Akkan
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudJonghyun Park
 
PHP cart
PHP cartPHP cart
PHP carttumetr1
 
Everything you need to know about PowerShell
Everything you need to know about PowerShellEverything you need to know about PowerShell
Everything you need to know about PowerShellShane Hoey
 
Implmenting an Experiment in oTree
Implmenting an Experiment in oTreeImplmenting an Experiment in oTree
Implmenting an Experiment in oTreeeurosigdoc acm
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Pavel Novitsky
 
Error based blind sqli
Error based blind sqliError based blind sqli
Error based blind sqliDarkZtone Zone
 
The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189Mahmoud Samir Fayed
 

Was ist angesagt? (20)

Jsoup Tutorial for Beginners - Javatpoint
Jsoup Tutorial for Beginners - JavatpointJsoup Tutorial for Beginners - Javatpoint
Jsoup Tutorial for Beginners - Javatpoint
 
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)JCConf 2015  - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
 
Jsoup tutorial
Jsoup tutorialJsoup tutorial
Jsoup tutorial
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
Web осень 2012 лекция 7
Web осень 2012 лекция 7Web осень 2012 лекция 7
Web осень 2012 лекция 7
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
Roman iovlev. Test UI with JDI - Selenium camp
Roman iovlev. Test UI with JDI - Selenium campRoman iovlev. Test UI with JDI - Selenium camp
Roman iovlev. Test UI with JDI - Selenium camp
 
Django Pro ORM
Django Pro ORMDjango Pro ORM
Django Pro ORM
 
Introduction to jQuery - The basics
Introduction to jQuery - The basicsIntroduction to jQuery - The basics
Introduction to jQuery - The basics
 
PHP webboard
PHP webboardPHP webboard
PHP webboard
 
yagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guideyagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guide
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
 
Practica n° 7
Practica n° 7Practica n° 7
Practica n° 7
 
PHP cart
PHP cartPHP cart
PHP cart
 
Everything you need to know about PowerShell
Everything you need to know about PowerShellEverything you need to know about PowerShell
Everything you need to know about PowerShell
 
Implmenting an Experiment in oTree
Implmenting an Experiment in oTreeImplmenting an Experiment in oTree
Implmenting an Experiment in oTree
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
 
Error based blind sqli
Error based blind sqliError based blind sqli
Error based blind sqli
 
The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189The Ring programming language version 1.6 book - Part 46 of 189
The Ring programming language version 1.6 book - Part 46 of 189
 

Ähnlich wie Django - A gyors és pragmatikus webfejlesztés alapjai

A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Jacob Kaplan-Moss
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1MicroPyramid .
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Djangocolinkingswood
 
Django for mobile applications
Django for mobile applicationsDjango for mobile applications
Django for mobile applicationsHassan Abid
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)Mike Dirolf
 
1Uso de DRF (Django Rest Framework).pptx
1Uso de DRF (Django Rest Framework).pptx1Uso de DRF (Django Rest Framework).pptx
1Uso de DRF (Django Rest Framework).pptxdanielfmd1
 
Custom web application development with Django for startups and Django-CRM intro
Custom web application development with Django for startups and Django-CRM introCustom web application development with Django for startups and Django-CRM intro
Custom web application development with Django for startups and Django-CRM introMicroPyramid .
 
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribTzu-ping Chung
 
DJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDamien Raczy
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheetLam Hoang
 

Ähnlich wie Django - A gyors és pragmatikus webfejlesztés alapjai (20)

A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django for mobile applications
Django for mobile applicationsDjango for mobile applications
Django for mobile applications
 
Django
DjangoDjango
Django
 
Tango with django
Tango with djangoTango with django
Tango with django
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
1Uso de DRF (Django Rest Framework).pptx
1Uso de DRF (Django Rest Framework).pptx1Uso de DRF (Django Rest Framework).pptx
1Uso de DRF (Django Rest Framework).pptx
 
Django (Web Konferencia 2009)
Django (Web Konferencia 2009)Django (Web Konferencia 2009)
Django (Web Konferencia 2009)
 
Django web framework
Django web frameworkDjango web framework
Django web framework
 
Discovering Django - zekeLabs
Discovering Django - zekeLabsDiscovering Django - zekeLabs
Discovering Django - zekeLabs
 
Custom web application development with Django for startups and Django-CRM intro
Custom web application development with Django for startups and Django-CRM introCustom web application development with Django for startups and Django-CRM intro
Custom web application development with Django for startups and Django-CRM intro
 
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
 
DJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptx
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
 

Mehr von Ferenc Szalai

Hardware Renaissance
Hardware RenaissanceHardware Renaissance
Hardware RenaissanceFerenc Szalai
 
Linux adattárolási képességei
Linux adattárolási képességeiLinux adattárolási képességei
Linux adattárolási képességeiFerenc Szalai
 
Virtualizáció Linuxon: XEN
Virtualizáció Linuxon: XENVirtualizáció Linuxon: XEN
Virtualizáció Linuxon: XENFerenc Szalai
 
Miért vagyok Python rajongó? - avagy kalandozások egy nyílt forrású programoz...
Miért vagyok Python rajongó? - avagy kalandozások egy nyílt forrású programoz...Miért vagyok Python rajongó? - avagy kalandozások egy nyílt forrású programoz...
Miért vagyok Python rajongó? - avagy kalandozások egy nyílt forrású programoz...Ferenc Szalai
 
CoLinux - avagy két dudás egy csárdában
CoLinux - avagy két dudás egy csárdábanCoLinux - avagy két dudás egy csárdában
CoLinux - avagy két dudás egy csárdábanFerenc Szalai
 
Mesterséges agyak - scifi és valóság határán
Mesterséges agyak - scifi és valóság határánMesterséges agyak - scifi és valóság határán
Mesterséges agyak - scifi és valóság határánFerenc Szalai
 
Emlekező áramköri elemek fizikája
Emlekező áramköri elemek fizikájaEmlekező áramköri elemek fizikája
Emlekező áramköri elemek fizikájaFerenc Szalai
 
Science Meetup bemutató
Science Meetup bemutatóScience Meetup bemutató
Science Meetup bemutatóFerenc Szalai
 
Nagy-teljesítményű, költséghatékony adattárolási technológiák könyvtári körny...
Nagy-teljesítményű, költséghatékony adattárolási technológiák könyvtári körny...Nagy-teljesítményű, költséghatékony adattárolási technológiák könyvtári körny...
Nagy-teljesítményű, költséghatékony adattárolási technológiák könyvtári körny...Ferenc Szalai
 
Adattároló klaszterek
Adattároló klaszterekAdattároló klaszterek
Adattároló klaszterekFerenc Szalai
 
Grid és adattárolás
Grid és adattárolásGrid és adattárolás
Grid és adattárolásFerenc Szalai
 
Klaszter és virtualizációs technikák
Klaszter és virtualizációs technikákKlaszter és virtualizációs technikák
Klaszter és virtualizációs technikákFerenc Szalai
 
Grid és adattárolás
Grid és adattárolásGrid és adattárolás
Grid és adattárolásFerenc Szalai
 
Grid Underground projekt
Grid Underground projektGrid Underground projekt
Grid Underground projektFerenc Szalai
 
Identity 2.0 - a vágy titogzatos tárgya
Identity 2.0 - a vágy titogzatos tárgyaIdentity 2.0 - a vágy titogzatos tárgya
Identity 2.0 - a vágy titogzatos tárgyaFerenc Szalai
 
Grid Underground (GUG) - avagy hogyan építsünk IT szolgáltatás hálózatot a su...
Grid Underground (GUG) - avagy hogyan építsünk IT szolgáltatás hálózatot a su...Grid Underground (GUG) - avagy hogyan építsünk IT szolgáltatás hálózatot a su...
Grid Underground (GUG) - avagy hogyan építsünk IT szolgáltatás hálózatot a su...Ferenc Szalai
 
Budapest New Technology Meetup - az elmúlt egy évünk
Budapest New Technology Meetup - az elmúlt egy évünkBudapest New Technology Meetup - az elmúlt egy évünk
Budapest New Technology Meetup - az elmúlt egy évünkFerenc Szalai
 
Az agy túlélő készlete - avagy tanulási tanácsok az iskolapad utáni mindennap...
Az agy túlélő készlete - avagy tanulási tanácsok az iskolapad utáni mindennap...Az agy túlélő készlete - avagy tanulási tanácsok az iskolapad utáni mindennap...
Az agy túlélő készlete - avagy tanulási tanácsok az iskolapad utáni mindennap...Ferenc Szalai
 
Alapvető beállítások egy levelező rendszer működéséhez
Alapvető beállítások egy levelező rendszer működéséhezAlapvető beállítások egy levelező rendszer működéséhez
Alapvető beállítások egy levelező rendszer működéséhezFerenc Szalai
 

Mehr von Ferenc Szalai (20)

Hardware Renaissance
Hardware RenaissanceHardware Renaissance
Hardware Renaissance
 
Linux adattárolási képességei
Linux adattárolási képességeiLinux adattárolási képességei
Linux adattárolási képességei
 
Virtualizáció Linuxon: XEN
Virtualizáció Linuxon: XENVirtualizáció Linuxon: XEN
Virtualizáció Linuxon: XEN
 
Miért vagyok Python rajongó? - avagy kalandozások egy nyílt forrású programoz...
Miért vagyok Python rajongó? - avagy kalandozások egy nyílt forrású programoz...Miért vagyok Python rajongó? - avagy kalandozások egy nyílt forrású programoz...
Miért vagyok Python rajongó? - avagy kalandozások egy nyílt forrású programoz...
 
CoLinux - avagy két dudás egy csárdában
CoLinux - avagy két dudás egy csárdábanCoLinux - avagy két dudás egy csárdában
CoLinux - avagy két dudás egy csárdában
 
Mesterséges agyak - scifi és valóság határán
Mesterséges agyak - scifi és valóság határánMesterséges agyak - scifi és valóság határán
Mesterséges agyak - scifi és valóság határán
 
Emlekező áramköri elemek fizikája
Emlekező áramköri elemek fizikájaEmlekező áramköri elemek fizikája
Emlekező áramköri elemek fizikája
 
Science Meetup bemutató
Science Meetup bemutatóScience Meetup bemutató
Science Meetup bemutató
 
Virtualization
VirtualizationVirtualization
Virtualization
 
Nagy-teljesítményű, költséghatékony adattárolási technológiák könyvtári körny...
Nagy-teljesítményű, költséghatékony adattárolási technológiák könyvtári körny...Nagy-teljesítményű, költséghatékony adattárolási technológiák könyvtári körny...
Nagy-teljesítményű, költséghatékony adattárolási technológiák könyvtári körny...
 
Adattároló klaszterek
Adattároló klaszterekAdattároló klaszterek
Adattároló klaszterek
 
Grid és adattárolás
Grid és adattárolásGrid és adattárolás
Grid és adattárolás
 
Klaszter és virtualizációs technikák
Klaszter és virtualizációs technikákKlaszter és virtualizációs technikák
Klaszter és virtualizációs technikák
 
Grid és adattárolás
Grid és adattárolásGrid és adattárolás
Grid és adattárolás
 
Grid Underground projekt
Grid Underground projektGrid Underground projekt
Grid Underground projekt
 
Identity 2.0 - a vágy titogzatos tárgya
Identity 2.0 - a vágy titogzatos tárgyaIdentity 2.0 - a vágy titogzatos tárgya
Identity 2.0 - a vágy titogzatos tárgya
 
Grid Underground (GUG) - avagy hogyan építsünk IT szolgáltatás hálózatot a su...
Grid Underground (GUG) - avagy hogyan építsünk IT szolgáltatás hálózatot a su...Grid Underground (GUG) - avagy hogyan építsünk IT szolgáltatás hálózatot a su...
Grid Underground (GUG) - avagy hogyan építsünk IT szolgáltatás hálózatot a su...
 
Budapest New Technology Meetup - az elmúlt egy évünk
Budapest New Technology Meetup - az elmúlt egy évünkBudapest New Technology Meetup - az elmúlt egy évünk
Budapest New Technology Meetup - az elmúlt egy évünk
 
Az agy túlélő készlete - avagy tanulási tanácsok az iskolapad utáni mindennap...
Az agy túlélő készlete - avagy tanulási tanácsok az iskolapad utáni mindennap...Az agy túlélő készlete - avagy tanulási tanácsok az iskolapad utáni mindennap...
Az agy túlélő készlete - avagy tanulási tanácsok az iskolapad utáni mindennap...
 
Alapvető beállítások egy levelező rendszer működéséhez
Alapvető beállítások egy levelező rendszer működéséhezAlapvető beállítások egy levelező rendszer működéséhez
Alapvető beállítások egy levelező rendszer működéséhez
 

Kürzlich hochgeladen

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Django - A gyors és pragmatikus webfejlesztés alapjai

  • 1. Django Szalai Ferenc (szferi@wsbricks.com)
  • 3. “Django egy magas szintű Python nyelven írt web alkalmazás keretrendszer, ami a gyors és pragmatikus alkalmazás fejlesztést támogatja.”
  • 5. előfeltétel: python, django forrás (svn, tar.gz) # cd django # python setup.py install http://www.djangoproject.com/documentation/install/
  • 6. Alapfogalmak ● Projekt ● Alkalmazas ● Model ● View ● Controller (URL) ● Template
  • 8. $ ls -l supporter/ __init__.py manage.py settings.py urls.py
  • 9. $ python manage.py runserver Validating models... 0 errors found Django version 1.1 beta 1, using settings 'supporter.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
  • 10. settings.py ● DATABASE_ENGINE ● DATABASE_NAME ● DATABASE_USER ● DATABASE_PASSWORD ● DATABASE_HOST ● normál python modul ● a saját konfig paramétereink legyenek nagybetűsek! ● http://www.djangoproject.com/documentation/settings/
  • 11. Alkalmazások ● logikai egység ● újrafelhasználható ● összetartozó model, view, url gyűjteménye ● $ python manage.py startapp topic
  • 13. INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'supporter.topic' )
  • 14. User Company django.contrib.auth Topic Topic djangon.contrib.comment Topic Comment supporter.topic Comment
  • 15. Model
  • 16. BEGIN; CREATE TABLE "topic_topic" ( "id" integer NOT NULL PRIMARY KEY, "author_id" integer NOT NULL, "type" varchar(1) NOT NULL, "title" varchar(128) NOT NULL, "content" text NOT NULL, "feeling" integer NOT NULL ) ; COMMIT;
  • 17. Az SQL csúnya A Python cool
  • 18. from django.db import models from django.contrib.auth.models import User class Topic(models.Model): TOPIC_TYPES = ( ('Q', 'Question'), ('I', 'Idea'), ('P', 'Problem'), ) author = models.ForeignKey(User) type = models.CharField(max_length=1, choices=TOPIC_TYPES) title = models.CharField(max_length=128) content = models.TextField() feeling = models.IntegerField() created = models.DateTimeField(auto_now_add=True)
  • 19. $ python manage.py validate $ python manage.py syncdb Creating table auth_permission Creating table auth_group Creating table auth_user Creating table auth_message Creating table django_content_type Creating table django_session Creating table django_site Creating table topic_topic You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'szferi'): E-mail address: szferi@wsbricks.com Password: Password (again): Superuser created successfully. Installing index for auth.Permission model Installing index for auth.Message model Installing index for topic.Topic model
  • 21. $ python manage.py shell In [1]: from supporter.topic.models import Topic In [2]: from django.contrib.auth.models import User In [3]: u = User.objects.get(id=1) In [4]: print u szferi In [5]: t = Topics.objects.create(author=u, type='Q', title='test', content='nagybaj!', feeling=-1) In [6]: print t Topic object In [7]: print t.title test In [8]: print Topic.objects.all() [<Topic: Topic object>] In [9]: ts = Topic.objects.filter(content__contains='baj') In [10]: print ts[0].content nagybaj!
  • 22. class Topic(models.Model): ... def __unicode__(self): return self.title
  • 23. $ python manage.py shell In [1]: from supporter.topic.models import Topic In [2]: print Topic.objects.all() [<Topic: test>]
  • 24. class Topic(models.Model): ... class Meta: ordering = ['created']
  • 26. from django.db import models from django.contrib.auth.models import User class Topic(models.Model): TOPIC_TYPES = ( ('Q', 'Question'), ('I', 'Idea'), ('P', 'Problem'), ) author = models.ForeignKey(User) type = models.CharField(max_length=1, choices=TOPIC_TYPES) title = models.CharField(max_length=128) content = models.TextField() feeling = models.IntegerField() created = models.DateTimeField(auto_now_add=True)
  • 27. $ python manage.py shell In [2]: from django.contrib.auth.models import User In [3]: u = User.objects.get(id=1) In [4]: print u szferi In [5]: print u.topic_set.all() [<Topic: test>] In [6]: print u.topic_set.filter(type='Q') [<Topic: test>]
  • 28. Views
  • 29. from django.http import HttpResponse def index(request): return HttpResponse('Hello!')
  • 31.
  • 32.
  • 34. from django.conf.urls.defaults import * import views urlpatterns = patterns('', (r'^$', views.index), (r'^(?P<topic>[0-9]*)/$', views.detail) )
  • 35. from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^topic/', include('supporter.topic.urls')), )
  • 37. from django.http import HttpResponse from supporter.topic.models import Topic def index(request): r = '<ul>' topics = Topic.objects.all() for t in topics: r += "<li>%s</li>" % t.title r += '</ul>' return HttpResponse(r)
  • 39. <html> <body> <p>There is {{ topics|length }} topics</p> <ul> {% for t in topics %} <li>{{ t.title }}</li> {% endfor %} </ul> </body> </html>
  • 40.
  • 42. from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), (r'^topic/', include('supporter.topic.urls')), )
  • 43.
  • 44.
  • 46. from models import Topic from django.forms import ModelForm class TopicForm(ModelForm): class Meta: model = Topic exclude = ('author', )
  • 47. def add(request): from forms import TopicForm from django.http import HttpResponseRedirect from django.contrib.auth.models import User if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = form.save(commit=False) topic.author = User.objects.get(id=1) topic.save() return HttpResponseRedirect('/') else: form = TopicForm() return render_to_response('add.html', {'form': form })
  • 48. <html> <body> <form method="post" action="."> {{ form }} <input type="submit" value="SAVE" name="save"/> </form> </body> </html>
  • 49. Hova tovább, hovatovább ● automatikus teszt ● saját template tag és filter ● session kezelés ● authentikáció ● cache ● l10n, i18n ● RSS/Atom ● Generikus view-k ● stb, stb.