Tuesday, February 22, 2011
Saturday, February 19, 2011
#1 Setup a basic Django project
, I've been getting more and more interested in Django. I think why shouldn't I write a series about it. So, let's start with the basics first: how to setup Django development environment and build a basic Django project.
1. Setup environments
To verify if it's already installed, at console:
$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
$ tar xzvf Django.tar.gz
$ cd Django
$ sudo python setup.py install
To verfiy what's your current Django's version
$ python
>>> import django
>>> django.get_version()
2. Create a basic Django project
This will create a basic Django project in mysite directory that looks as below
mysite/
__init__.py
manage.py
settings.py
urls.py
Validating models...
0 errors found.
Django version 1.0, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
1. Setup environments
- Install Python
To verify if it's already installed, at console:
$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
- Install Django
$ tar xzvf Django.tar.gz
$ cd Django
$ sudo python setup.py install
To verfiy what's your current Django's version
$ python
>>> import django
>>> django.get_version()
2. Create a basic Django project
- To initialize project
This will create a basic Django project in mysite directory that looks as below
mysite/
__init__.py
manage.py
settings.py
urls.py
- Now run a development webserver to see if your Django site works
Validating models...
0 errors found.
Django version 1.0, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
- Goto http://127.0.0.1:8000 on your Web browser, you'll see a "Welcome to Django" page. It's works!
Friday, February 18, 2011
How caching works in Django
Last time, I had a chance joining to a Django project. Django is a web framework written by Python. Though I've invested sometime before to study Django and been amazing with it, I haven't really done anything on Django yet. So that's a good opportunity for me to increase my Django knowledge. One of my tasks at start was to study caching supports in Django. Compare to what I knew with Ruby on Rails, I found that caching in Django is very strong and especially well-organized. So, it would be useful to put some summarizations down here.
- General rule
given a URL, try finding that page in the cache
if the page is in the cache:
return the cached page
else:
generate the page
save the generated page in the cache (for next time)
return the generated page
- More specific
- Advantages and disadvantages of caching backends
Advantages Disadvantages Memcached
- the fastest, most efficient type of cache available to Django
- all cached data is stored directly in memory, so there’s no overhead of database or filesystem usage
- cached data can be shared over multiple machines, so it’s excellent for scaling
- being used by Facebook, Wikipedia,...
- cached data is stored in memory, so it will be lost if server crashes (but it’s not critical because cached data is just temporary)
- need to have memcached daemon along the wayIn-database cached
- cached data is persistent
- could use multiple databases for caching
- setup & manage multiple caching databases would be toughFilesystem cached
- cached data is persistent
- simple to setup
- may not scale wellLocal-memory cached
- simple
- not nescessary to have runing an external cache server as memcached
- no cross-process caching means it’s not particularly memory-efficient
- probably not a good choice for production, just nice for development
- Reference
http://docs.djangoproject.com/en/1.2/topics/cache/
Subscribe to:
Posts (Atom)