-
Notifications
You must be signed in to change notification settings - Fork 0
level_1 is done #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| venv/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ | |
| from django_views_routing_homework.views.level_2.a_user_info_by_username import get_user_info_by_username_view | ||
| from django_views_routing_homework.views.level_2.c_product_type import get_products_view | ||
| from django_views_routing_homework.views.level_2.d_authorization import authorization_view, process_authorization_view | ||
| from django_views_routing_homework.views.level_1.b_bye_user import bye_user_view | ||
| from django_views_routing_homework.views.level_1.d_user_info import get_user_info_view | ||
| from django_views_routing_homework.views.level_1.e_month_title import get_month_title_view | ||
|
|
||
|
|
||
| urlpatterns = [ | ||
| path('admin/', admin.site.urls), | ||
|
|
@@ -15,5 +19,8 @@ | |
| path('products/', get_products_view), | ||
| path('authorization/', authorization_view), | ||
| path('process-authorization/', process_authorization_view), | ||
| # добавлять пути тут | ||
| path('bye/', bye_user_view), | ||
| path('user-info/<int:user_id>/', get_user_info_view), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 используем path parameter с заданным типом при маппинге на вьюху |
||
| path('month-title/<int:month_number>/', get_month_title_view), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 все верно, задаем номер месяца как числовой path parameter |
||
| ] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,5 +10,5 @@ | |
|
|
||
|
|
||
| def welcome_user_view(request): | ||
| welcome_message = 'Bye, user' | ||
| welcome_message = 'Hello, user' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 верно |
||
| return HttpResponse(welcome_message) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,5 +14,7 @@ | |
|
|
||
|
|
||
| def is_username_banned_view(request, username: str): | ||
| # код писать тут | ||
| return HttpResponse('User not banned') | ||
| if username in BANNED_USERNAMES: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 верно |
||
| return HttpResponse('User banned') | ||
| else: | ||
| return HttpResponse('User not banned') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,33 @@ | |
| вызывалась вьюха get_month_title_view. Например http://127.0.0.1:8000/month-title/3/ | ||
| """ | ||
|
|
||
| MONTHS = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 словарь хорошо подходит для такой задачи |
||
| 1: 'Январь', | ||
| 2: 'Февраль', | ||
| 3: 'Март', | ||
| 4: 'Апрель', | ||
| 5: 'Май', | ||
| 6: 'Июнь', | ||
| 7: 'Июль', | ||
| 8: 'Август', | ||
| 9: 'Сентябрь', | ||
| 10: 'Октябрь', | ||
| 11: 'Ноябрь', | ||
| 12: 'Декабрь', | ||
| } | ||
|
|
||
|
|
||
| def get_month_title_by_number(month_number: int): | ||
| pass # код писать тут | ||
| if month_number in MONTHS: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 верно return MONTHS.get(month_number) |
||
| return MONTHS[month_number] | ||
| else: | ||
| return None | ||
|
|
||
|
|
||
| def get_month_title_view(request, month_number: int): | ||
| # код писать тут | ||
| return HttpResponseNotFound('Месяца с таким номером не существует') | ||
| month_title = get_month_title_by_number(month_number) | ||
|
|
||
| if month_title: | ||
| return HttpResponse(month_title) | ||
| else: | ||
| return HttpResponseNotFound('Месяца с таким номером не существует') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 верно |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 верно, замапили путь на вьюху-обработчик