Створити простий багатороздільний вебсайт компанії з чіткою структурою URL та коректною обробкою неіснуючих (помилкових) адрес.
| Розділ | Базова адреса | Приклади неправильних адрес, які все одно показують розділ |
|---|
| // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there. | |
| // | |
| #include <iostream> | |
| int main() | |
| { | |
| std::cout << "Hello World!\n"; | |
| } |
| // client.cpp | |
| // компілювати: clang++ -std=c++17 -o client client.cpp -pthread | |
| // запуск: ./client | |
| #include <iostream> | |
| #include <cstring> | |
| #include <unistd.h> | |
| #include <sys/socket.h> | |
| #include <netinet/in.h> | |
| #include <arpa/inet.h> |
| // server.cpp | |
| // компілювати: clang++ -std=c++17 -o server server.cpp -pthread | |
| // запуск: ./server | |
| #include <iostream> | |
| #include <cstring> | |
| #include <unistd.h> | |
| #include <sys/socket.h> | |
| #include <netinet/in.h> | |
| #include <arpa/inet.h> |
| from django.http import ( | |
| HttpResponse, | |
| JsonResponse, | |
| HttpResponseRedirect, | |
| FileResponse, | |
| StreamingHttpResponse, | |
| ) | |
| from django.shortcuts import render | |
| import os | |
| import time |
| urls.py: | |
| from django.urls import path | |
| from . import views | |
| urlpatterns = [ | |
| path('', views.home, name='home'), # головна сторінка | |
| path('json/', views.json_response, name='json-response'), # JsonResponse | |
| path('redirect/', views.redirect_example, name='redirect'), # HttpResponseRedirect | |
| path('file/', views.file_response, name='file-response'), # FileResponse |
| NewApp / weather / urls.py: | |
| from django.urls import path | |
| from . import views | |
| urlpatterns = [ | |
| path('', views.request_demo, name='request-demo'), | |
| path('submit/', views.handle_form, name='submit-form'), | |
| ] |
| NewApp / weather / urls.py: | |
| from django.urls import path, re_path, register_converter | |
| from django.http import HttpResponse | |
| from . import views | |
| # кастомний конвертер | |
| class FourDigitYearConverter: | |
| """Кастомний конвертер для років 1000–9999""" | |
| regex = r'[1-9]\d{3}' # чотири цифри, перша не нуль |
| NewApp / weather / views.py: | |
| from django.shortcuts import render | |
| from django.http import HttpResponse | |
| def hello(request): | |
| return HttpResponse("<h1>Привіт! Це сторінка з додатка weather 🌤️</h1>") | |
| ############################################################################################## |
| views.py: | |
| from django.http import HttpResponse | |
| import requests # для запитів в інтернет | |
| # cd C:\Users\Alex\Desktop\DjangoWebProject1 | |
| # env\Scripts\activate | |
| # py -m pip install requests | |
| def main_page(request): # http://localhost:58566 | |
| return HttpResponse("головна сторінка!") |