Open
Conversation
vppuzakov
approved these changes
Sep 27, 2023
|
|
||
| def welcome_user_view(request): | ||
| welcome_message = 'Bye, user' | ||
| welcome_message = 'Hello, user' |
| path('authorization/', authorization_view), | ||
| path('process-authorization/', process_authorization_view), | ||
| # добавлять пути тут | ||
| path('bye/', bye_user_view), |
There was a problem hiding this comment.
👍 верно, замапили путь на вьюху-обработчик
| def is_username_banned_view(request, username: str): | ||
| # код писать тут | ||
| return HttpResponse('User not banned') | ||
| if username in BANNED_USERNAMES: |
| 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.
👍 используем path parameter с заданным типом при маппинге на вьюху
| вызывалась вьюха get_month_title_view. Например http://127.0.0.1:8000/month-title/3/ | ||
| """ | ||
|
|
||
| MONTHS = { |
There was a problem hiding this comment.
👍 словарь хорошо подходит для такой задачи
|
|
||
| def get_month_title_by_number(month_number: int): | ||
| pass # код писать тут | ||
| if month_number in MONTHS: |
There was a problem hiding this comment.
👍 верно
💡 еще чтобы два раза не искать элемент в словаре, можно было бы использовать get метод словаря
return MONTHS.get(month_number)| if month_title: | ||
| return HttpResponse(month_title) | ||
| else: | ||
| return HttpResponseNotFound('Месяца с таким номером не существует') No newline at end of file |
| # добавлять пути тут | ||
| path('bye/', bye_user_view), | ||
| path('user-info/<int:user_id>/', get_user_info_view), | ||
| path('month-title/<int:month_number>/', get_month_title_view), |
There was a problem hiding this comment.
👍 все верно, задаем номер месяца как числовой path parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.