build website in_django

23
BUILD WEBSITE IN DJANGO WITH A SEARCH ENGINE IN THE END

Upload: swee-meng-ng

Post on 07-Nov-2014

4.865 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Build website in_django

BUILD WEBSITE IN DJANGO

WITH A SEARCH ENGINE IN THE END

Page 2: Build website in_django

DJANGO?

a Web development frameworkWritten in PythonOriginally used in a News SiteNow used in many place

Page 3: Build website in_django

FEATURES

It comes with

ORM Administration SiteDevelopment ToolsTemplatesForm validationAuthentication FrameworkComments FrameworkFeedsAnd many more

Page 4: Build website in_django

ENOUGH TALKING

LET GET TO WORK

Page 5: Build website in_django

LADIES AND GENTLEMEN

Start your project, by using the command django-admin startproject projectname

You should see the content in the new folder__init__.py manage.py settings.py urls.py

Page 6: Build website in_django

CONFIGURE IT A LITTLE

The settings is in settings.py we start with the databasefind the similar template in settings.py** show settings.pyhttp://gist.github.com/376201

Page 7: Build website in_django

A LITTLE MORE

here find the line in settings.pyfind the same similar in settings and change it accordingly** show template_dirshttp://gist.github.com/376203

Page 8: Build website in_django

PHEW.....

Now we can start working,

after we python manage.py startapp issues

Now we really can start workingbtw you should see the following

__init__.py models.py tests.py views.py

Page 9: Build website in_django

WHILE WE AT IT

Lets get a enable admin page in urls.pychange the part in settings.py**show settings.py

http://gist.github.com/376207

and urls.py**show urls.pyhttp://gist.github.com/376208

Page 10: Build website in_django

WHO WANT TO BE A MODEL?

model.py == database table (almost)copy into models.py**shows issues modelshttp://gist.github.com/376205

Page 11: Build website in_django

SETUP A APP

now save the models.py

add application in settings.py

this is just part of settings.py**show examplehttp://gist.github.com/376207

create in issue/admin.py**show admin.py

http://gist.github.com/376210

Page 12: Build website in_django

SYNC IT!!!!

Now we can create a database,

python manage.py syncdb

python mange.py runserver

**show admin page

Page 13: Build website in_django

FIRST SUBMIT A FORM

One cool aspect of django is you can automate form generation, free with validation!!!!

create this one in issue/forms.py** show form.py

http://gist.github.com/376290

Page 14: Build website in_django

NOW TO VIEW THE APPS

lets create django views

add the following**show add view**show item view**show list viewhttp://gist.github.com/376304

Page 15: Build website in_django

TEMPLATING

Django uses template to present to user, let start with a main template, and the template for app

** show base.htmlhttp://gist.github.com/376294** show add.htmlhttp://gist.github.com/376297** show view.htmlhttp://gist.github.com/376298** show list.htmlhttp://gist.github.com/376300

Page 16: Build website in_django

URL.PY

now lets create a url to point to the webappcreate this one** show issue/urls.pyhttp://gist.github.com/376310

modify from the template** show urls.pyhttp://gist.github.com/376311and demo

Page 17: Build website in_django

EXTRA!!!!

NOW A REVIEW OF HAYSTACK

Page 18: Build website in_django

FINDING NEEDLE IN HAYSTACK

Haystack is a search api for django, it support several backend, including solr, whoosh,

Page 19: Build website in_django

A LITTLE SETUP(AGAIN)

Let do a little setup

git clone http://github.com/toastdriven/django-haystack.git

**show changes in settings.pyhttp://gist.github.com/376659

**show search_indexhttp://gist.github.com/376662

Page 20: Build website in_django

TELL HAYSTACK WHICH NEEDLE

We create a search index

** show search indexhttp://gist.github.com/376668

** search document place on <template dir>/search/indexes/issue/issue_text.txthttp://gist.github.com/376672

Page 21: Build website in_django

NOW TELL SOLR

Create solr index, and run index

create a schema.xml for solrpython manage.py build_solr_schema > schema.xml

create search indexpython manage.py rebuild_index

Page 22: Build website in_django

NOW CREATE A SEARCH SITE

We just reuse the search view** show urls.pyadd (r'^search/',include("haystack.urls"))

and create a template** show search/search.htmlhttp://gist.github.com/376685

Page 23: Build website in_django

VOILA!!!

Now we have a basic search.

except haystack can do quite a lot, which is another story altogether