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
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
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