Skip to content

Latest commit

 

History

History
249 lines (193 loc) · 7.65 KB

README.md

File metadata and controls

249 lines (193 loc) · 7.65 KB

Django Trainingen

Learning Django

  1. Read the [Django Book][book], it is excellent
  2. Read the [Django docs][docs] [book]:http://www.djangobook.com/en/2.0/ [docs]:https://docs.djangoproject.com/en/1.3/

Community

  1. django-users mailing list
  2. django-developers mailing list
  3. irc: #django
  4. DjangoCons and Django Meetings
  5. contribute?

Useful shortcuts

  1. render, since Django 1.3.
  • render() is the same as a call to render_to_response() with a context_instance argument that forces the use of a RequestContext.
  1. redirect, since Django 1.1, usage:
  • redirects to:
    1. an object, with defined get_absolute_url
    1. a named url
    1. a hardcoded url (relative or full)

in views.py

from django.shortcuts import render
return render(request, 'my_template.html', context)

from django.shortcuts import redirect
return redirect('name_of_url')

Use named urls

models.py:

class Car(models.Model):
    ...

    def get_absolute_url():
        return reverse('car')

urls.py

url(r'/(\d+)/', 'car.views.car', name='car')

views.py

return redirect('car', car.id)

in cars.html template:

{% for car in cars %}
    <a href="{{ car.get_absolute_url }}">car.name</a>
{% endfor %}

Middleware and context processors

  1. Middleware
  2. Context processors

Examples

  1. django.contrib.auth.AuthenticationMiddleware
  2. django.contrib.auth.context_processors

Github

https://github.com/

For example: django-debug-toolbar django-debug-toolbar:https://github.com/django-debug-toolbar/django-debug-toolbar

[Creating a repository][create-git-repo] [create-git-repo]:http://help.github.com/create-a-repo/

Git and github

Set up git

git config --global user.name "Wim Feijen"
git config --global user.email [email protected]

Next steps:

mkdir Django-Trainingen
cd Django-Trainingen
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin [email protected]:wimfeijen/Django-Trainingen.git
git push -u origin master

Upload ssh key?

https://github.com/account/ssh

Existing Git Repo?

cd existing_git_repo
git remote add origin [email protected]:wimfeijen/Django-Trainingen.git
git push -u origin master

Git

Updating the repo

  • git add
  • git status
  • git commit -m 'Description of the change'
  • git push

Creating a branch

  • git clone

Update your branch

  • git pull

Markdown

[Basics][markdown-basics] [markdown-basics]:http://daringfireball.net/projects/markdown/basics

[Syntax][markdown-syntax] [markdown-syntax]:http://daringfireball.net/projects/markdown/syntax

What’s new in Django 1.2

  1. Improved CSRF protection
  2. Messages framework
  3. Relaxed requirements for usernames
  4. Email backends
  5. “Smart” if tag
  6. Improved localization
  7. readonly_fields in ModelAdmin
  8. JavaScript-assisted handling of inline related objects in the admin

Ad 6. in settings.py:

USE_I10N = True 

What’s new in Django 1.3

  1. Class-based views
  2. Logging
  3. Extended static files handling

Recommendations

  1. Django packages
  2. Django snippets
  3. Django people
  4. Github

Likes

Javascript

Tips

About the author

Wim Feijen