# Instale o Python
~ $ sudo apt-get install python3
# Instale o pip (gerenciador de pacotes)
~ $ sudo apt-get install python3-pip
# OPCIONAL: Crie um ambiente virtual
~ $ sudo pip install virtualenv
~ $ virtualenv novo_ambiente --python=/usr/bin/python3
~ $ source novo_ambiente/bin/activate
# Finalmente, instale o Django :)
~ $ pip install django
# Execute o comando
~ $ django-admin startproject meuprojeto .
# Será criada a seguinte estrutura:
~
|
├─ manage.py # script de gerenciamento
└─ meuprojeto
settings.py # configurações do projeto
urls.py # lista de mapeamentos de urls
wsgi.py
__init__.py
# Dentro da pasta do projeto
~ $ python manage.py runserver
# Rodar no diretório do projeto
~ $ python manage.py startapp app
~ # A nova estrutura do projeto
├── manage.py
├── meuprojeto
| ... # idem ao slide anterior
└── app
├── migrations
| __init__.py
├── __init__.py
├── admin.py
├── models.py
├── tests.py
└── views.py
Fonte: http://www.slideshare.net/balakumarp/django-framework
from django.db import models
from django.utils import timezone
class Post(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^articles/([0-9]{4})/$',
views.year_archive),
url(r'^articles/([0-9]{4})/([0-9]{2})/$',
views.month_archive),
url(r'^articles/([0-9]{4})/([0-9]{2})/([0-9]+)/$',
views.article_detail),
]
from django.shortcuts import render
from .models import Article
def year_archive(request, year):
a_list = Article.objects.filter(pub_date__year=year)
context = {'year': year, 'article_list': a_list}
return render(request, 'news/year_archive.html', context)
{% extends "base.html" %}
{% block title %}Articles for {{ year }}{% endblock %}
{% block content %}
Articles for {{ year }}
{% for article in article_list %}
{{ article.headline }}
By {{ article.reporter.full_name }}
Published {{ article.pub_date|date:"F j, Y" }}
{% endfor %}
{% endblock %}
Fonte: Quora.com - What-are-some-well-known-sites-running-on-Django
-=[ "live long and prosper" ]=-
_
.-T | _
| | | / |
| | | / /`|
_ | | |/ / /
\`\| '.' / /
\ \`-. '--|
\ ' |
\ .` /
| |