Skip to content

almanuel/django-gs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Django Getting Started

Taking notes.

Part 1

django-admin startproject mysite python manage.py startapp <app-name>

  • Views and urls.

Part 2

  • settings.py: Set timezone

  • Database usage: python manage.py migrate

Models

  • Models Fields
  • settings.py plug apps in INSTALLED_APPS variable.

Migrations

  • makemigrations command.
  • sqlmigrate command
  • migrate command.

Shell

python manage.py shell

Model CRUD operations on admin

Suppose a polls app and a Question model, on polls/admin.py file add:

from .models import Question
admin.site.register(Question)

That's it.

Models API

  • Queries, get, filters.`

Part 3

  • New views on new urls.
  • Templates. Read more here.
  • Raising 404 error
    • raise django.http.Http404("Some message")
    • Shortcuts: get_object_or_404() and get_list_or_404()
  • Removing hardcoded URLs in templates, e.g:
<a href="{% url 'detail' question.id %}">{{ question.question_text }}</a>
  • Define app namespaces with app_name in urls.py.

Part 4

  • Simple forms
  • Generic Views

About

Getting started on the Django framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published