From 20a0a3c7e3ab87a10fa2e777eb2c08e7a35057dc Mon Sep 17 00:00:00 2001 From: Saeid Javadi Date: Mon, 18 Nov 2024 20:39:38 +0330 Subject: [PATCH] Update some content and tag issues --- source/_posts/django.md | 262 ++++++++++++++++++----------- source/_posts/windows-shortcuts.md | 4 +- 2 files changed, 165 insertions(+), 101 deletions(-) diff --git a/source/_posts/django.md b/source/_posts/django.md index 0085307..f42e807 100644 --- a/source/_posts/django.md +++ b/source/_posts/django.md @@ -110,10 +110,14 @@ Migrate: Will read the migrations files and create the actual database and table ## Project config {.cols-1} ### Configuration settings + ##### Project base templates directory and Apps templates directory: - - create folder project/templates - - create folder appfolder/templates/appname + +- create folder project/templates +- create folder appfolder/templates/appname + ##### Create Static folder in base root and separate for apps: + - project_name\static\root - app_name\static\app_name @@ -521,23 +525,21 @@ path('/update/', PostsUpdateView.as_view(), name='post-update') Templates are store in `project_folder/templates` or in your app_folder/templates/app_name/\*.html - - -```django -# Extend from another template -# can use the same parts of your HTML for different template +```html + + {% extends 'base.html' %} -# A part of the parent template that is defined and is replaced by a part in the child template + {% block contents %} {% endblock contents %} -# include template + {% include 'partials/header.html' %} -# include template with One or More Parameters + {% include 'body.html' with key1=value1 key2=value2 %} -# If statement in template + {% if user.username = 'Mike' %}

Hello Admin

{% elif user.username = 'john' %} @@ -546,7 +548,7 @@ Templates are store in `project_folder/templates` or in your app_folder/te

Hello User

{% endif %} -# for loop in template + {% for product in products %}

row: {{ forloop.counter }} # starting index 1 @@ -556,40 +558,40 @@ Templates are store in `project_folder/templates` or in your app_folder/te

The product name is {{ product.price }}

{% endfor %} -# Access to the variable in the template + {{ var_name }} -# Template variables formating + {{ title | lower }} {{ blog.post | truncatwords:50 }} {{ order.date | date:"D M Y" }} {{ list_items | slice:":3" }} {{ total | default:"nil" }} -# Current path (ex. posts/1/show) + {{ request.path }} -# URL by name with param + {% url 'posts.delete' id=post.id %} -# Use static in template: + {% load static %} {% static 'css/main.css' %} -# Define the variable in the template + {% with name="World" %}

Hello {{ name }}!
{% endwith %} -# Template translate text + {% load i18n %} {% trans "This is the title." %} -# Use variable translate in the template + {% trans object.title %} -# Define the list in the template + app_folder/te step="1" {% endif %}> -# Safely Pass Data to JavaScript in a Django Template: -#+ Use data attributes for simple values + + -#+ Separate script files: can use document.currentScript for separate script files + -#+ Case conversion + -# Read it in JavaScript as fullName: -const data = document.currentScript.dataset; -const fullName = data.fullName; + + -#+ Non-string types + -# parseInt() to convert this value from a string: -const data = document.currentScript.dataset; -const followerCount = parseInt(data.followerCount, 10); -#+ There’s no limit: A + +