On Github chamindu / rad-django
Chamindu R. Munasinghe chamindu@calcey.com@chamindum
Python package index
A repository of around 51k packages
Package manager for Python
$ pip install django
$ pip install -r requirements.txt
Isolated working environments
Cannot run multiple python versions
All apps share same packages and versions
A command line tool to easily manage virtualenv's in development
"The Web framework for perfectionists with deadlines"
Disqus, Instagram, Pinterest, Bitbucket and many more
Create a simple "polls" app
$ django-admin.py startproject mysite
The app is already configured to use sqlite
$ python manage.py startapp polls
Add it to the INSTALLED_APPS
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
$ python manage.py makemigrations polls
$ python manage.py migrate
Basic CRUD operations with zero code
from django.contrib import admin
from polls.models import Question
admin.site.register(Question)
from django.contrib import admin
from polls.models import Question, Choice
class ChoiceInline(admin.StackedInline):
model = Choice
extra = 3
class QuestionAdmin(admin.ModelAdmin):
inlines = [ChoiceInline]
admin.site.register(Question, QuestionAdmin)
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
# polls/urls.py
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
)
# urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
class IndexView(generic.ListView):
model = Question
<html>
<head></head>
<body>
<ul>
{% for question in object_list %}
<li><a href="{% url 'detail' question.id %}">
{{ question.question_text }}
</a></li>
{% empty %}
<li>No polls</li>
{% endfor %}
</ul>
</body>
</html>
nginx and uWSGI recommended