//membuat project django django-admin startproject firstdjango
//menjalankan server python manage.py runserver 10.4.68.72:7000
//menjalankan migrate (untuk fill database) python manage.py migrate
//membuat superuser di admin python manage.py createsuperuser
//membuat konten di django python manage.py startapp products python manage.py startapp blog python manage.py startapp profiles python manage.py startapp cart
//mengatur models
/************** Create Product Objects in the Python Shell ***************/ python manage.py shell from products.models import Product Product.objects.all() Product.objects.create(title='New product 2', description="another one", price="1000", summary="hello")
/************** New Model Field ***************/ references https://docs.djangoproject.com/en/3.1/ref/models/fields/#model-field-types
/************** Change a Model ***************/ boolean harus mempunyai default value
/************** Default Homepage to Custom Homepage ***************/ check files: - products/view.py
/************** URL Routing and Requests ***************/ def contactView(*args, **kwargs): return HttpResponse("
")def aboutView(*args, **kwargs): return HttpResponse("
")def socialView(*args, **kwargs): return HttpResponse("
")/************** Django templates***************/
/************** Django templating Engine Basics ***************/ check files: - templates/home.html - templates/base.html
/************** Include Template Tag ***************/ {% include 'navbar.html' %}
/************** Rendering Context in a Template ***************/ my_context = { "my_text": "this is about us", "my_number": 123, "my_list": [123, 4323, 12313] }
{{ my_text }}, {{ my_number }}
/************** For Loop in a Template ***************/
-
{% for my_item in my_list %}
- {{ forloop.counter }} - {{ my_item }} {% endfor %}
/************** Using Conditions in a Template ***************/
-
{% for my_item in my_list %}
{% if my_item == 123 %}
- {{ forloop.counter }} - {{ my_item|add:22 }} {% elif my_item == 'testing' %}
- This is not an integer {% else %}
- {{ forloop.counter }} - {{ my_item }} {% endif %}
{% endfor %}
/************** Template Tags and Filters ***************/ references: https://docs.djangoproject.com/en/3.1/ref/templates/builtins/
/************** Render Data from the Database with a Model ***************/
/************** How Django Templates Load with Apps ***************/
/************** Raw HTML Form ***************/