Skip to content

riiamri23/learndjango

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

//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("

Contact Page

")

def aboutView(*args, **kwargs): return HttpResponse("

About Page

")

def socialView(*args, **kwargs): return HttpResponse("

Social Page

")

/************** 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 ***************/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published