I wrote a function which after execution returns the user to the anchor page. But I'm getting an error.
TypeError: quote_from_bytes() expected bytes
view.py
class CourseEditView(AuthorizedMixin, UpdateView):
"""
Edit course instances
"""
model = Courses
form_class = CoursesEditForm
template_name = 'additional_info_edit.html'
def get_success_url(self):
pk = self.object.employee.pk
return redirect('{}#education'.format(reverse('profile', kwargs={'pk': pk})))
How to avoid a mistake?
UPD traceback
Traceback (most recent call last):
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/home/y700/projects/CV/cv-base/ems/base/views.py", line 35, in dispatch
return super().dispatch(*args, **kwargs)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/views/generic/edit.py", line 194, in post
return super().post(request, *args, **kwargs)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/views/generic/edit.py", line 142, in post
return self.form_valid(form)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/views/generic/edit.py", line 126, in form_valid
return super().form_valid(form)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/views/generic/edit.py", line 57, in form_valid
return HttpResponseRedirect(self.get_success_url())
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/http/response.py", line 456, in __init__
self['Location'] = iri_to_uri(redirect_to)
File "/home/y700/Env/cv-base-XRtgVf2K/lib/python3.7/site-packages/django/utils/encoding.py", line 148, in iri_to_uri
return quote(iri, safe="/#%[]=:;$&()+,!?*@'~")
File "/home/y700/anaconda3/lib/python3.7/urllib/parse.py", line 791, in quote
return quote_from_bytes(string, safe)
File "/home/y700/anaconda3/lib/python3.7/urllib/parse.py", line 816, in quote_from_bytes
raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes
[30/Jul/2019 10:04:33] "POST /course/11/edit/ HTTP/1.1" 500 133528
According to the documentation, get_success_url
should just return the URL to redirect to, not the redirect response
return '{}#education'.format(reverse('profile', kwargs={'pk': pk}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With