First Thing You Should Do After Install Django, Create Main Page or Redirect It

  • Posted on: 7 April 2015
  • By: oon
First Thing You Should Do After Install Django, Create Main Page or Redirect It

This is something that I repeatly do after finish install Django, add main page (home page) or simply redirect it to another website.

here's simple example of inside your Django project folder.

from django.views.generic import RedirectView

urlpatterns = [
    url(r'^$', view=RedirectView.as_view(url='')),

This is how you can avoid others to know your (still on debug mode) urls or URL mapping.


Django Model Serializer

  • Posted on: 5 April 2015
  • By: oon

How to serialize model to JSON on Django?

Django has serializers module on it's core.

from django.core import serializers 
from myproject.myapp import models 
data = serializers.serialize("json", models.MyModel.objects.all())

really simple :)


Jinja2 syntax equivalent to Django's URL name and static

  • Posted on: 4 April 2015
  • By: oon
Django's template URL name like for Jinja2

(after start using Jinja2 on Django)

I need to use Django syntax {% url %} in Jinja2, here's my reference [1].

{{ url('index', args=[variable]) }}

And Django syntax {% static %} also similar.

{{ static('path') }}

hope it helps!



Install and Start Project Django

  • Posted on: 2 April 2015
  • By: oon

Install Django with pip package manager, for example inside (virtual) environment, install version 1.8 LTS:

pip install "django < 1.9"

You can check your install version (not only using pip also) with command django-admin

django-admin --version

 for example it will output: 1.8

Now we are ready to create Django project:

django-admin startproject rdjango

it will create directory rdjango, and inside the directory there will be these files: