Команди за всички индивидуални мрежови интерфейси на нашата машина
Mac/Linux:
bash
ifconfig
Windows:
bash
ipconfig /all
Физически интерфейси: en0, en1, en2, en3, en4, en5, en6
Request/Response - Client/Server
Сървъра е машината, която може да предоставя ресурси
terminal
curl https://softuni.bg/
Network Protocol
Често използвани протоколи:
Пакети
Протокола е начина, по който, съръра и клиента разбират как да обработват пакетите.
IP адрес
IPv4 vs IPv6
v6 позволява създаването на 3.4×10^38 уникални адреса
DNS - Domain Name System
IP-то се сменя, затова не можем да караме потребителте да го помнят
HTTP
URL (Uniform Resource Locator)
Можем да имаме url-и на кирилица
MIME (Multi-purpose Internet Mail Extensions)
Получаваме готови функции
MVT Pattern
Model View Template
Структура на Django проект
djangoApp - всеки app се грижи за отделна част от нашия проект
Creation of a django app
urls.py filesettings.pybash
python manage.py runserver
setting.pymodels.pymakemigrationsmigrate
Views
Трябват ни:
python
def index(request):
return HttpResponse("Hello world")
python
HttpResponse("Hello world", headers={
"Content-Type": "application/json",
})urls
urlpatterns в app/urls.pyВ нея задаваме на какъв път, какво view да се изпълни ```python from .views import index
urlpatterns = (
path('home/', index),
)
- Добавяме си app/urls в project/urls.pypython
urlpatterns = (
path('admin/', admin.site.urls),
path('', include('project_name.app_name.urls')),
)
```
Admin Panel
createsuperuser9, Django Template Language (DTL)
- Като динамичен HTML
- Имаме цикли, ифове
- Можем да рендерираме наши стойности
- {{ }} - интерполация
- {% %} - template tags
python
urlpatterns = [
path('index/', index_view),
path('index/', index_view_2) # никога няма да видим index_view_2
]
```python urlpatterns = [ path('admin/', admin.site.urls), path('departments/', include('departments.urls')), ]
```
include може да приема списък от paths
Динамични url-и
python
path('index/<int:pk> ', index_view),Типове динамични url-и
python
re_path(r'^article/(?P<year>[0-9]{4})/', view)
# matches year and saves it in a variable yearViews
Function Based Views
Response types
python
return HttpResponse(content="Hi my name is", status=201)JsonResponse ```python content = json.dumps({ "name": "Dido", "age": 20 })
return HttpResponse(content=content, content_type="application/json")
return JsonResponse(content,) ```
Django Shortcuts
python
return render(request, 'core/index.html', context) # context is optionalpython
redirect('https://softuni.bg') # използваме абсолютен url. защото редиректваме към друго приложение
redirect('my_view_name', pk=10) # използваме име на view-то, за по-добра абстракцияpython
article = get_object_or_404(Article, pk=article_id)reverse_lazy
python
# settings.py
LOGIN_URL = reverse('index') # throws an error
LOGIN_URL = reverse_lazy('index') # throws an errorDjango Errors
404.html Jinja2Настройките по подразбиране за DTL можем да намерим в settings.py
python
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates']
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Променливи
{{ }}{{ my_list.1 }}, {{ person.full_name }}, {{ my_object.items }}
python
context = {
"person": {
"name": "Dido"
"age": 20,
},
"person2": Person(name="Metodi", age="21 "
}
Филтри
| : Линк към всички филтри в Django -> Django Template Filters
Тагове
```html <!-- Example of if,
$ claude mcp add Django-Basics \
-- python -m otcore.mcp_server <graph>