Я все еще младший разработчик в Django и веб-фрейме. Работа над созданием системы управления коворкингом в django 3. На странице профиля пользователя, когда они нажимают кнопку «Изменить профиль», они получают эту ошибку.
Примечание: редактирование профиля с использованием 'admin' работает отлично, без ошибок. но пользователи сами получают эту ошибку. если есть какие-либо детали, необходимые больше, я опубликую это.
Вот обратная связь:
Traceback (most recent call last):
File "/home/maha/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/maha/venv/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/maha/venv/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/maha/venv/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/home/maha/venv/nadine/member/views/profile.py", line 232, in edit_profile
return render(request, 'member/profile/profile_edit.html', context)
File "/home/maha/venv/lib/python3.7/site-packages/django/shortcuts.py", line 19, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/loader.py", line 62, in render_to_string
return template.render(context, request)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/test/utils.py", line 95, in instrumented_test_render
return self.nodelist.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/test/utils.py", line 95, in instrumented_test_render
return self.nodelist.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 992, in render
return render_value_in_context(output, context)
File "/home/maha/venv/lib/python3.7/site-packages/django/template/base.py", line 971, in render_value_in_context
value = str(value)
File "/home/maha/venv/lib/python3.7/site-packages/django/utils/html.py", line 373, in <lambda>
klass.__str__ = lambda self: mark_safe(klass_str(self))
File "/home/maha/venv/lib/python3.7/site-packages/django/forms/boundfield.py", line 33, in __str__
return self.as_widget()
File "/home/maha/venv/lib/python3.7/site-packages/django/forms/boundfield.py", line 89, in as_widget
attrs = self.build_widget_attrs(attrs, widget)
File "/home/maha/venv/lib/python3.7/site-packages/django/forms/boundfield.py", line 224, in build_widget_attrs
if widget.use_required_attribute(self.initial) and self.field.required and self.form.use_required_attribute:
File "/home/maha/venv/lib/python3.7/site-packages/django/forms/widgets.py", line 699, in use_required_attribute
first_choice = next(iter(self.choices), None)
File "/home/maha/venv/lib/python3.7/site-packages/django/forms/fields.py", line 757, in __iter__
yield from self.choices_func()
Exception Type: TypeError at /member/profile/salem_otaibi/edit/
Exception Value: 'NoneType' object is not iterable
, а вот profile.py:
@login_required
def edit_profile(request, username):
user = get_object_or_404(User, username=username)
if not user == request.user:
if not request.user.is_staff:
return HttpResponseRedirect(reverse('member:profile:view', kwargs={'username': request.user.username}))
LinkFormSet = formset_factory(LinkForm, formset=BaseLinkFormSet)
user_links = user.profile.websites.all()
link_data = [{'url_type': l.url_type, 'url': l.url, 'username': user.username} for l in user_links]
if request.method == 'POST':
profile_form = EditProfileForm(request.POST)
link_formset = LinkFormSet(request.POST)
profile_form.public_profile = request.POST['public_profile']
if profile_form.is_valid():
if link_formset.is_valid():
if request.POST.get('password-create') == request.POST.get('password-confirm'):
pwd = request.POST.get('password-create')
if len(pwd.strip()) > 0:
if pwd.strip() == pwd and len(pwd) > 7:
profile_form.save()
user.set_password(pwd)
user.save()
return HttpResponseRedirect(reverse('member:profile:view', kwargs={'username': user.username}))
else:
messages.error(request, 'Your password must be at least 8 characters long.')
else:
for link in link_data:
del_url = link.get('url')
user.profile.websites.filter(url=del_url).delete()
for link_form in link_formset:
if not link_form.cleaned_data.get('username'):
link_form.cleaned_data['username'] = user.username
try:
if link_form.is_valid():
url_type = link_form.cleaned_data.get('url_type')
url = link_form.cleaned_data.get('url')
if url_type and url:
link_form.save()
except Exception as e:
messages.add_message(request, messages.ERROR, "Could not save: %s" % str(e))
profile_form.save()
return HttpResponseRedirect(reverse('member:profile:view', kwargs={'username': user.username}))
else:
messages.error(request,'The entered passwords do not match. Please try again.')
else:
messages.error(request, 'There was an error saving your websites. Please make sure they have a valid URL and URL type.')
else:
link_formset = LinkFormSet(initial=link_data)
profile = user.profile
emergency_contact = user.get_emergency_contact()
profile_form = EditProfileForm(initial={'username': user.username,
'first_name': user.first_name,
'last_name': user.last_name,
'email': user.email,
'phone': profile.phone, 'phone2': profile.phone2,
'address1': profile.address1, 'address2': profile.address2, 'city': profile.city, 'state': profile.state, 'zipcode': profile.zipcode,
'url_personal': profile.url_personal, 'url_professional': profile.url_professional,
'url_facebook': profile.url_facebook, 'url_twitter': profile.url_twitter,
'url_linkedin': profile.url_linkedin, 'url_github': profile.url_github,
'bio': profile.bio, 'photo': profile.photo,
'public_profile': profile.public_profile,
'gender': profile.gender, 'pronouns': profile.pronouns,
'howHeard': profile.howHeard, 'industry': profile.industry, 'neighborhood': profile.neighborhood,
'has_kids': profile.has_kids, 'self_employed': profile.self_employed,
'emergency_name': emergency_contact.name, 'emergency_relationship': emergency_contact.relationship,
'emergency_phone': emergency_contact.phone, 'emergency_email': emergency_contact.email,
})
context = {'user': user, 'profile_form': profile_form, 'link_formset': link_formset}
return render(request, 'member/profile/profile_edit.html', context)
любая помощь будет быть оцененным Спасибо