Может кто-нибудь объяснить часть небольшой кусок кода Django? - PullRequest
0 голосов
/ 03 марта 2020

Я следовал этому учебнику и пытался реализовать инструмент обновления профиля. Один фрагмент кода, который они предоставили, был следующим:

@login_required
@transaction.atomic
def update_profile(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, _('Your profile was successfully updated!'))
            return redirect('settings:profile')
        else:
            messages.error(request, _('Please correct the error below.'))
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'profiles/profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })

Мне удалось выяснить, что все это означало, кроме строки

return redirect('settings:profile')

После изменения переменных я получил ошибку :

NoReverseMatch в / profile /

'settings' не является зарегистрированным пространством имен

Нужно ли создавать что-то еще? Любая помощь будет оценена.

1 Ответ

0 голосов
/ 03 марта 2020

Для перенаправления требуется ваше имя или URL-адрес

Вызов: - redirect ('profile')

профиль определяет имя представления в вашем файле url.

url like : - путь ('profile', profileView, name = 'profile'),

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...