SlideShare a Scribd company logo
1 of 37
Download to read offline
PYLADIES PRESENTS:
Build your own blog
   with Django!


                      1
{{ GOALS }}
         Have fun
Learn about web development
     Create something



                              2
{{ LAYOUT }}

Overview of Django Framework
       Code together




                               3
{{ DJANGO }}

Django is to Python
        as
  Rails is to Ruby

                      4
{{ LET’S GET STARTED }}
            Quick note:
         do NOT copy text
on these slides into your text editor.
        Write it out yourself.

                                         5
{{ LET’S GET STARTED }}
   Activate your virtualenv
    $ workon MyBlog
           or
C:UserDesktopProjects
 MyBlogToolsScripts
       activate
                              6
{{ LET’S GET STARTED }}
     Start a Python shell

   (MyBlog)$ python
   And type ‘import django’

   >>> import django
                              7
{{ LET’S GET STARTED }}
Back in the terminal (NOT in the
 python shell), type (one line):

   (MyBlog)$ django-admin.py
  startproject ZagrebWorkshop



                                   8
{{ RUNSERVER }}
  On the terminal/console:
(MyBlog)$ python manage.py runserver


   In a web browser, go to:
        http://localhost:8000


         BAM it works.
                                       9
{{ SETTINGS.PY }}
 Open up settings.py
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.sqlite3',
         'NAME': 'MyBlog.db',
         'USER': '',
         'PASSWORD': '',
         'HOST': '',
         'PORT': '',
     }
 }
                                                   10
{{ SYNCDB }}
  Back on the terminal/console:
(MyBlog)$ python manage.py syncdb


      and follow prompts.
     BAM your DB is set up.

                                    11
{{ STARTAPP }}
  Back on the terminal/console:
(MyBlog)$ python manage.py startapp MyBlog

(MyBlog)$ cd MyBlog

(MyBlog)$ ls
     OR
(MyBlog)C:UserDesktop> dir

           BAM more files!
                                             12
{{ MODELS.PY }}
            Open up models.py
from django.db import models

class Post(models.Model):
    title = models.CharField(max_length=60)
    body = models.TextField()
    created = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return self.title


                                                        13
{{ SETTINGS.PY }}
     Return to settings.py file.
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'MyBlog',
)
                                                               14
{{ SYNCDB }}
Back on the terminal/console:
 (MyBlog)$ python manage.py syncdb

        again. Then do:
  (MyBlog)$ python manage.py shell


  Let’s play around a little.
                                     15
{{ SETTINGS.PY }}
     Return to settings.py file.
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'MyBlog',
)
                                                               16
{{ ADMIN }}
   Something is missing.
Create MyBlog/admin.py
from django.contrib import admin

from MyBlog.models import Post

class PostAdmin(admin.ModelAdmin):
    search_fields = ['title']

admin.site.register(Post, PostAdmin)

                                       17
{{ ADMIN }}
Back on the terminal/console:
(MyBlog)$ python manage.py runserver


   In a web browser, go to:
     http://localhost:8000/admin


              woah.
                                       18
{{ URLS }}
             Open urls.py
       And edit for the following:
from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
)

                                                      19
{{ ADMIN }}
Back on the terminal/console:
(MyBlog)$ python manage.py runserver


   In a web browser, go to:
     http://localhost:8000/admin


              woah.
                                       20
{{ URLS }}
    Now go to:

 http://localhost:8000


Missing something...


                         21
{{ URLS }}
            Reopen urls.py
       And edit for the following:
from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', ‘MyBlog.views.home’, name='home'),
    url(r'^(d+)/$', ‘MyBlog.views.post’, name='post'),
    url(r'^admin/', include(admin.site.urls)),
)

                                                          22
{{ ADMIN }}
Back on the terminal/console:
(MyBlog)$ python manage.py runserver


   In a web browser, go to:
       http://localhost:8000/

       Hrmph. No Views.
                                       23
{{ VIEWS }}
Open views.py...

And let’s write two
 views together.


                      24
{{ TEMPLATES }}
Download http://l.ynn.me/SVaCxp &
       unzip/open the file.


      Move the “templates”
     folder to under the main
   “ZagrebWorkshop” directory.
                                    25
{{ TEMPLATES }}

  Move the “static” folder
   to under the second
“ZagrebWorkshop” directory.


                              26
{{ TEMPLATES }}
           Optional: open
 “ZagrebWorkshop/templates/blog/
base.html” and edit for Author, Email,
           and/or Site Title

                                     27
{{ TEMPLATES }}
Optional: If you created a Disqus
 account, copy and paste your
       JavaScript code in:
“ZagrebWorkshop/templates/blog/
           post.html”
                                    28
{{ DIRECTORIES }}
   !"" ZagrebWorkshop/
       #"" MyBlog/
       $   #"" __init__.py
       $   #"" admin.py
       $   #"" models.py
       $   #"" tests.py
       $   #"" views.py
       #"" ZagrebWorkshop/
       $   #"" __init__.py
       $   #"" settings.py
       |   !"" static/
       $   #"" urls.py
       $   #"" wsgi.py
       #"" manage.py
       #"" MyBlog.db
       !"" templates/
           !"" blog/
                             29
{{ SETTINGS.PY }}
      Reopen settings.py
   and add these few bits.
Refer to notes for specific line
          numbers.
https://gist.github.com/4144268
                                  30
{{ COLLECTSTATIC }}

(MyBlog)$ python manage.py collectstatic




                                       31
{{ TA-DA }}
          One last time
(MyBlog)$ python manage.py runserver


    You should see your blog!


                                       32
{{ SETUP HEROKU }}

     Make a venv snapshot
(MyBlog)$ pip freeze > requirements.txt




                                          33
{{ SETUP HEROKU }}
  Make a new file called “Procfile”
       and save it in your main
     “ZagrebWorkshop” directory
web: python manage.py runserver 0.0.0.0:$PORT
                 --noreload


                                                34
{{ SETUP HEROKU }}
 $ git config --global user.name “Your Name”
$ git config --global user.email “Your Email”
                  $ git init
                 $ git add .
   $ git commit -m “My Django Application”




                                            35
{{ SETUP HEROKU }}
       (MyBlog) $ heroku login
       (MyBlog) $ heroku create

Follow the steps for ‘heroku create’.
 Take note of the URL that Heroku
    gives you on your terminal
  (MyBlog) $ git push heroku master
                                        36
{{ DEPLOY }}
 (MyBlog) $ git push heroku master

It may take a couple of minutes.
  Then, navigate to that URL
       from previous step

                                     37

More Related Content

What's hot

Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Michael Peacock
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War StoriesJakub Zalas
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Jakub Zalas
 
PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switc...
PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switc...PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switc...
PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switc...Puppet
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Yevhen Kotelnytskyi
 
Filling the flask
Filling the flaskFilling the flask
Filling the flaskJason Myers
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Yevhen Kotelnytskyi
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and othersYusuke Wada
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perldeepfountainconsulting
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2Graham Dumpleton
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Yusuke Wada
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -Yusuke Wada
 

What's hot (20)

IOS 11 setup with appium latest
IOS 11 setup with appium  latestIOS 11 setup with appium  latest
IOS 11 setup with appium latest
 
Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012
 
Symfony War Stories
Symfony War StoriesSymfony War Stories
Symfony War Stories
 
Kyiv.py #17 Flask talk
Kyiv.py #17 Flask talkKyiv.py #17 Flask talk
Kyiv.py #17 Flask talk
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Authoring CPAN modules
Authoring CPAN modulesAuthoring CPAN modules
Authoring CPAN modules
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
Generators
GeneratorsGenerators
Generators
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switc...
PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switc...PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switc...
PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switc...
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0
 
Filling the flask
Filling the flaskFilling the flask
Filling the flask
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
 
Lviv 2013 d7 vs d8
Lviv 2013   d7 vs d8Lviv 2013   d7 vs d8
Lviv 2013 d7 vs d8
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
 

Viewers also liked

Euro pythonslides
Euro pythonslidesEuro pythonslides
Euro pythonslidesLynn Root
 
Para Politikasi
Para PolitikasiPara Politikasi
Para Politikasiserdar635
 
Avoid Drowning
Avoid DrowningAvoid Drowning
Avoid DrowningLynn Root
 
Kredi Derecelendirme
Kredi DerecelendirmeKredi Derecelendirme
Kredi Derecelendirmeserdar635
 
Bicra Methodology 110911
Bicra Methodology 110911Bicra Methodology 110911
Bicra Methodology 110911serdar635
 
French projectt
French projecttFrench projectt
French projecttcn10068
 
Sarah skills presentation
Sarah skills presentationSarah skills presentation
Sarah skills presentationSarahlambert0
 

Viewers also liked (9)

Euro pythonslides
Euro pythonslidesEuro pythonslides
Euro pythonslides
 
Para Politikasi
Para PolitikasiPara Politikasi
Para Politikasi
 
Avoid Drowning
Avoid DrowningAvoid Drowning
Avoid Drowning
 
Kredi Derecelendirme
Kredi DerecelendirmeKredi Derecelendirme
Kredi Derecelendirme
 
Bicra Methodology 110911
Bicra Methodology 110911Bicra Methodology 110911
Bicra Methodology 110911
 
French projectt
French projecttFrench projectt
French projectt
 
Sarah skills presentation
Sarah skills presentationSarah skills presentation
Sarah skills presentation
 
Marketing
MarketingMarketing
Marketing
 
Combustion Associates Inc. Corporate Profile
Combustion Associates Inc. Corporate ProfileCombustion Associates Inc. Corporate Profile
Combustion Associates Inc. Corporate Profile
 

Similar to Zagreb workshop

Virtual Environment and Web development using Django
Virtual Environment and Web development using DjangoVirtual Environment and Web development using Django
Virtual Environment and Web development using DjangoSunil kumar Mohanty
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Yuriy Senko
 
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
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesLeonardo Fernandes
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Python Ireland
 
Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8Allie Jones
 
Django_3_Tutorial_and_CRUD_Example_with.pdf
Django_3_Tutorial_and_CRUD_Example_with.pdfDjango_3_Tutorial_and_CRUD_Example_with.pdf
Django_3_Tutorial_and_CRUD_Example_with.pdfDamien Raczy
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design PatternsBobby Bouwmann
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 

Similar to Zagreb workshop (20)

Virtual Environment and Web development using Django
Virtual Environment and Web development using DjangoVirtual Environment and Web development using Django
Virtual Environment and Web development using Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)
 
Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico Ces
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)
 
Django
DjangoDjango
Django
 
Django crush course
Django crush course Django crush course
Django crush course
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
Intro django
Intro djangoIntro django
Intro django
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8
 
Django_3_Tutorial_and_CRUD_Example_with.pdf
Django_3_Tutorial_and_CRUD_Example_with.pdfDjango_3_Tutorial_and_CRUD_Example_with.pdf
Django_3_Tutorial_and_CRUD_Example_with.pdf
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 

Recently uploaded

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Zagreb workshop

  • 1. PYLADIES PRESENTS: Build your own blog with Django! 1
  • 2. {{ GOALS }} Have fun Learn about web development Create something 2
  • 3. {{ LAYOUT }} Overview of Django Framework Code together 3
  • 4. {{ DJANGO }} Django is to Python as Rails is to Ruby 4
  • 5. {{ LET’S GET STARTED }} Quick note: do NOT copy text on these slides into your text editor. Write it out yourself. 5
  • 6. {{ LET’S GET STARTED }} Activate your virtualenv $ workon MyBlog or C:UserDesktopProjects MyBlogToolsScripts activate 6
  • 7. {{ LET’S GET STARTED }} Start a Python shell (MyBlog)$ python And type ‘import django’ >>> import django 7
  • 8. {{ LET’S GET STARTED }} Back in the terminal (NOT in the python shell), type (one line): (MyBlog)$ django-admin.py startproject ZagrebWorkshop 8
  • 9. {{ RUNSERVER }} On the terminal/console: (MyBlog)$ python manage.py runserver In a web browser, go to: http://localhost:8000 BAM it works. 9
  • 10. {{ SETTINGS.PY }} Open up settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'MyBlog.db', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', } } 10
  • 11. {{ SYNCDB }} Back on the terminal/console: (MyBlog)$ python manage.py syncdb and follow prompts. BAM your DB is set up. 11
  • 12. {{ STARTAPP }} Back on the terminal/console: (MyBlog)$ python manage.py startapp MyBlog (MyBlog)$ cd MyBlog (MyBlog)$ ls OR (MyBlog)C:UserDesktop> dir BAM more files! 12
  • 13. {{ MODELS.PY }} Open up models.py from django.db import models class Post(models.Model): title = models.CharField(max_length=60) body = models.TextField() created = models.DateTimeField(auto_now_add=True) def __unicode__(self): return self.title 13
  • 14. {{ SETTINGS.PY }} Return to settings.py file. INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'MyBlog', ) 14
  • 15. {{ SYNCDB }} Back on the terminal/console: (MyBlog)$ python manage.py syncdb again. Then do: (MyBlog)$ python manage.py shell Let’s play around a little. 15
  • 16. {{ SETTINGS.PY }} Return to settings.py file. INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'MyBlog', ) 16
  • 17. {{ ADMIN }} Something is missing. Create MyBlog/admin.py from django.contrib import admin from MyBlog.models import Post class PostAdmin(admin.ModelAdmin): search_fields = ['title'] admin.site.register(Post, PostAdmin) 17
  • 18. {{ ADMIN }} Back on the terminal/console: (MyBlog)$ python manage.py runserver In a web browser, go to: http://localhost:8000/admin woah. 18
  • 19. {{ URLS }} Open urls.py And edit for the following: from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), ) 19
  • 20. {{ ADMIN }} Back on the terminal/console: (MyBlog)$ python manage.py runserver In a web browser, go to: http://localhost:8000/admin woah. 20
  • 21. {{ URLS }} Now go to: http://localhost:8000 Missing something... 21
  • 22. {{ URLS }} Reopen urls.py And edit for the following: from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^$', ‘MyBlog.views.home’, name='home'), url(r'^(d+)/$', ‘MyBlog.views.post’, name='post'), url(r'^admin/', include(admin.site.urls)), ) 22
  • 23. {{ ADMIN }} Back on the terminal/console: (MyBlog)$ python manage.py runserver In a web browser, go to: http://localhost:8000/ Hrmph. No Views. 23
  • 24. {{ VIEWS }} Open views.py... And let’s write two views together. 24
  • 25. {{ TEMPLATES }} Download http://l.ynn.me/SVaCxp & unzip/open the file. Move the “templates” folder to under the main “ZagrebWorkshop” directory. 25
  • 26. {{ TEMPLATES }} Move the “static” folder to under the second “ZagrebWorkshop” directory. 26
  • 27. {{ TEMPLATES }} Optional: open “ZagrebWorkshop/templates/blog/ base.html” and edit for Author, Email, and/or Site Title 27
  • 28. {{ TEMPLATES }} Optional: If you created a Disqus account, copy and paste your JavaScript code in: “ZagrebWorkshop/templates/blog/ post.html” 28
  • 29. {{ DIRECTORIES }} !"" ZagrebWorkshop/ #"" MyBlog/ $   #"" __init__.py $   #"" admin.py $   #"" models.py $   #"" tests.py $   #"" views.py #"" ZagrebWorkshop/ $   #"" __init__.py $   #"" settings.py | !"" static/ $   #"" urls.py $   #"" wsgi.py #"" manage.py #"" MyBlog.db !"" templates/ !"" blog/ 29
  • 30. {{ SETTINGS.PY }} Reopen settings.py and add these few bits. Refer to notes for specific line numbers. https://gist.github.com/4144268 30
  • 31. {{ COLLECTSTATIC }} (MyBlog)$ python manage.py collectstatic 31
  • 32. {{ TA-DA }} One last time (MyBlog)$ python manage.py runserver You should see your blog! 32
  • 33. {{ SETUP HEROKU }} Make a venv snapshot (MyBlog)$ pip freeze > requirements.txt 33
  • 34. {{ SETUP HEROKU }} Make a new file called “Procfile” and save it in your main “ZagrebWorkshop” directory web: python manage.py runserver 0.0.0.0:$PORT --noreload 34
  • 35. {{ SETUP HEROKU }} $ git config --global user.name “Your Name” $ git config --global user.email “Your Email” $ git init $ git add . $ git commit -m “My Django Application” 35
  • 36. {{ SETUP HEROKU }} (MyBlog) $ heroku login (MyBlog) $ heroku create Follow the steps for ‘heroku create’. Take note of the URL that Heroku gives you on your terminal (MyBlog) $ git push heroku master 36
  • 37. {{ DEPLOY }} (MyBlog) $ git push heroku master It may take a couple of minutes. Then, navigate to that URL from previous step 37