On Github asmaps / django-presentation
made by Arne Schauf @asmaps
26.10.2014 - NetHack 2014
* 23.1.1910✝ 16.5.1953
Created with Raphaël 2.1.0
from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns( '', url(r'^allauth/', include('allauth.urls')), url(r'^accounts/', include('accounts.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^', include('main.urls')), )
from django.conf.urls import patterns, url from django.views.generic import TemplateView from main.views import ( HomeView, HelpView, AboutView, ...) ... urlpatterns = patterns( '', url(r'^$', HomeView.as_view(), name="home"), url(r'^about/$', AboutView.as_view(), name="about"), url(r'^legal/$', TemplateView.as_view(template_name='main/legal.html'), name="legal"), url(r'^help/$', HelpView.as_view(), name="help"), ... )
# urls.py url(r'^evaluate/(?P<id>\d+)/$', 'main.views.evaluate'),
# views.py @login_required def evaluate(request, id): return render_to_response( 'evaluate/evaluate.html', { 'questionnaire' : Questionnaire.objects.get(id=id), 'active' : 'evaluate', }, context_instance=RequestContext(request) )
# urls.py url(r'^about/$', AboutView.as_view(), name="about"),
# views.py from django.views.generic import TemplateView class AboutView(TemplateView): template_name = "main/about.html"
# urls.py url(r'^(?P<slug>[a-zA-Z0-9_\-]+)/$', HostDetailView.as_view(), name="info"),
# views.py from django.views.generic import DetailView class HostDetailView(DetailView): model = Host template_name = 'host/detail.html'
# models.py from django.db import models class Host(models.Model): subdomain = models.CharField(max_length=256, validators=[ RegexValidator( regex=r'^(([a-z0-9][a-z0-9\-]*[a-z0-9])|[a-z0-9])$', message='Invalid subdomain: only a-z, 0-9 and - are allowed' ), domain_blacklist_validator]) domain = models.ForeignKey(Domain) update_secret = models.CharField(max_length=256) comment = models.CharField( max_length=256, default='', blank=True, null=True)
# models.py from django.db import models class BaseModel(models.Model): modified = models.DateTimeField(auto_now=True) created = models.DateTimeField(auto_now_add=True) class Meta: abstract = True class Comment(BaseModel): comment = models.TextField() class Value(BaseModel): value = models.IntegerField()
# forms.py from django import forms class BeginEndForm(forms.Form): begin = forms.DateField() end = forms.DateField()
# views.py from django.views.generic import FormView class CalcDayDifferenceView(FormView): form_class = BeginEndForm def form_valid(self, form): diff = form.cleaned_data['end'] - form.cleaned_data['begin'] # do sth with the difference ...
{# calc_day_difference.html #} ... {% csrf_token %} {{ form }} ....
# models.py from django.db import models class Thing(models.Model): related_thing = models.ForeignKey('Thing', null=True, blank=True) name = models.CharField(max_length=255, help_text='The name of the thing')
# views.py from django.views.generic import CreateView from .models import Thing class CreateThingView(CreateView): model = Thing
# thing_form.html
# admin.py from django.contrib import admin from things.models import Thing admin.site.register(Thing)
asmaps:~/example_project > python manage.py makemigrations things Migrations for 'things': 0001_initial.py: - Create model Thing
asmaps:~/example_project > python manage.py migrate Operations to perform: Apply all migrations: admin, things, contenttypes, auth, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying sessions.0001_initial... OK Applying things.0001_initial... OK
Webserver:
Datenbanken:
Me imagining what microframeworks are like
Offizielle Docs:https://docs.djangoproject.com
Online-Tutorials:http://twoscoopspress.com/pages/django-tutorials
Buch:Two Scoops of Django
Diese Präsentation:http://asmaps.github.io/django-presentation/
Reveal.js:https://github.com/hakimel/reveal.js
Markus Zapke-Gründemann:http://www.django-introduction.com/
Raphaël.js:http://raphaeljs.com/
Dieses Werk steht unter einer Creative Commons Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Unported Lizenz