0
PYLADIES PRESENTS:Build your own blog   with Django!                      1
{{ GOALS }}         Have funLearn 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 texton these slides into your text editor.        Write...
{{ LET’S GET STARTED }}   Activate your virtualenv    $ workon MyBlog           orC:UserDesktopProjects MyBlogToolsScripts...
{{ LET’S GET STARTED }}     Start a Python shell   (MyBlog)$ python   And type ‘import django’   >>> import django        ...
{{ LET’S GET STARTED }}Back in the terminal (NOT in the python shell), type (one line):   (MyBlog)$ django-admin.py  start...
{{ RUNSERVER }}  On the terminal/console:(MyBlog)$ python manage.py runserver   In a web browser, go to:        http://loc...
{{ SETTINGS.PY }} Open up settings.py DATABASES = {     default: {         ENGINE: django.db.backends.sqlite3,         NAM...
{{ SYNCDB }}  Back on the terminal/console:(MyBlog)$ python manage.py syncdb      and follow prompts.     BAM your DB is s...
{{ STARTAPP }}  Back on the terminal/console:(MyBlog)$ python manage.py startapp MyBlog(MyBlog)$ cd MyBlog(MyBlog)$ ls    ...
{{ MODELS.PY }}            Open up models.pyfrom django.db import modelsclass Post(models.Model):    title = models.CharFi...
{{ SETTINGS.PY }}     Return to settings.py file.INSTALLED_APPS = (    django.contrib.auth,    django.contrib.contenttypes,...
{{ SYNCDB }}Back on the terminal/console: (MyBlog)$ python manage.py syncdb        again. Then do:  (MyBlog)$ python manag...
{{ SETTINGS.PY }}     Return to settings.py file.INSTALLED_APPS = (    django.contrib.auth,    django.contrib.contenttypes,...
{{ ADMIN }}   Something is missing.Create MyBlog/admin.pyfrom django.contrib import adminfrom MyBlog.models import Postcla...
{{ ADMIN }}Back on the terminal/console:(MyBlog)$ python manage.py runserver   In a web browser, go to:     http://localho...
{{ URLS }}             Open urls.py       And edit for the following:from django.conf.urls import patterns, include, urlfr...
{{ ADMIN }}Back on the terminal/console:(MyBlog)$ python manage.py runserver   In a web browser, go to:     http://localho...
{{ URLS }}    Now go to: http://localhost:8000Missing something...                         21
{{ URLS }}            Reopen urls.py       And edit for the following:from django.conf.urls import patterns, include, urlf...
{{ ADMIN }}Back on the terminal/console:(MyBlog)$ python manage.py runserver   In a web browser, go to:       http://local...
{{ 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 t...
{{ 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,           a...
{{ TEMPLATES }}Optional: If you created a Disqus account, copy and paste your       JavaScript code in:“ZagrebWorkshop/tem...
{{ DIRECTORIES }}   !"" ZagrebWorkshop/       #"" MyBlog/       $   #"" __init__.py       $   #"" admin.py       $   #"" m...
{{ SETTINGS.PY }}      Reopen settings.py   and add these few bits.Refer to notes for specific line          numbers.https:...
{{ COLLECTSTATIC }}(MyBlog)$ python manage.py collectstatic                                       31
{{ TA-DA }}          One last time(MyBlog)$ python manage.py runserver    You should see your blog!                       ...
{{ SETUP HEROKU }}     Make a venv snapshot(MyBlog)$ pip freeze > requirements.txt                                        ...
{{ SETUP HEROKU }}  Make a new file called “Procfile”       and save it in your main     “ZagrebWorkshop” directoryweb: pyth...
{{ SETUP HEROKU }} $ git config --global user.name “Your Name”$ git config --global user.email “Your Email”               ...
{{ SETUP HEROKU }}       (MyBlog) $ heroku login       (MyBlog) $ heroku createFollow the steps for ‘heroku create’. Take ...
{{ DEPLOY }} (MyBlog) $ git push heroku masterIt may take a couple of minutes.  Then, navigate to that URL       from prev...
Upcoming SlideShare
Loading in...5
×

Zagreb workshop

666

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
666
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Zagreb workshop"

  1. 1. PYLADIES PRESENTS:Build your own blog with Django! 1
  2. 2. {{ GOALS }} Have funLearn about web development Create something 2
  3. 3. {{ LAYOUT }}Overview of Django Framework Code together 3
  4. 4. {{ DJANGO }}Django is to Python as Rails is to Ruby 4
  5. 5. {{ LET’S GET STARTED }} Quick note: do NOT copy texton these slides into your text editor. Write it out yourself. 5
  6. 6. {{ LET’S GET STARTED }} Activate your virtualenv $ workon MyBlog orC:UserDesktopProjects MyBlogToolsScripts activate 6
  7. 7. {{ LET’S GET STARTED }} Start a Python shell (MyBlog)$ python And type ‘import django’ >>> import django 7
  8. 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. 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. 10. {{ SETTINGS.PY }} Open up settings.py DATABASES = { default: { ENGINE: django.db.backends.sqlite3, NAME: MyBlog.db, USER: , PASSWORD: , HOST: , PORT: , } } 10
  11. 11. {{ SYNCDB }} Back on the terminal/console:(MyBlog)$ python manage.py syncdb and follow prompts. BAM your DB is set up. 11
  12. 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. 13. {{ MODELS.PY }} Open up models.pyfrom django.db import modelsclass 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. 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. 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. 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. 17. {{ ADMIN }} Something is missing.Create MyBlog/admin.pyfrom django.contrib import adminfrom MyBlog.models import Postclass PostAdmin(admin.ModelAdmin): search_fields = [title]admin.site.register(Post, PostAdmin) 17
  18. 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. 19. {{ URLS }} Open urls.py And edit for the following:from django.conf.urls import patterns, include, urlfrom django.contrib import adminadmin.autodiscover()urlpatterns = patterns(, url(r^admin/, include(admin.site.urls)),) 19
  20. 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. 21. {{ URLS }} Now go to: http://localhost:8000Missing something... 21
  22. 22. {{ URLS }} Reopen urls.py And edit for the following:from django.conf.urls import patterns, include, urlfrom django.contrib import adminadmin.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. 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. 24. {{ VIEWS }}Open views.py...And let’s write two views together. 24
  25. 25. {{ TEMPLATES }}Download http://l.ynn.me/SVaCxp & unzip/open the file. Move the “templates” folder to under the main “ZagrebWorkshop” directory. 25
  26. 26. {{ TEMPLATES }} Move the “static” folder to under the second“ZagrebWorkshop” directory. 26
  27. 27. {{ TEMPLATES }} Optional: open “ZagrebWorkshop/templates/blog/base.html” and edit for Author, Email, and/or Site Title 27
  28. 28. {{ TEMPLATES }}Optional: If you created a Disqus account, copy and paste your JavaScript code in:“ZagrebWorkshop/templates/blog/ post.html” 28
  29. 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. 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. 31. {{ COLLECTSTATIC }}(MyBlog)$ python manage.py collectstatic 31
  32. 32. {{ TA-DA }} One last time(MyBlog)$ python manage.py runserver You should see your blog! 32
  33. 33. {{ SETUP HEROKU }} Make a venv snapshot(MyBlog)$ pip freeze > requirements.txt 33
  34. 34. {{ SETUP HEROKU }} Make a new file called “Procfile” and save it in your main “ZagrebWorkshop” directoryweb: python manage.py runserver 0.0.0.0:$PORT --noreload 34
  35. 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. 36. {{ SETUP HEROKU }} (MyBlog) $ heroku login (MyBlog) $ heroku createFollow the steps for ‘heroku create’. Take note of the URL that Heroku gives you on your terminal (MyBlog) $ git push heroku master 36
  37. 37. {{ DEPLOY }} (MyBlog) $ git push heroku masterIt may take a couple of minutes. Then, navigate to that URL from previous step 37
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×